Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($httpbackend): ie11 api changes for jsonp #4527

Closed
wants to merge 1 commit into from
Closed

fix($httpbackend): ie11 api changes for jsonp #4527

wants to merge 1 commit into from

Conversation

eddiemonge
Copy link
Contributor

IE11 changed their script api and no longer uses onreadystatechange. It
now follows other browsers with onload and onerror

Fixes #4523

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@btford
Copy link
Contributor

btford commented Oct 19, 2013

Before we accept this, we need to get IE11 up and running on our CI server. IE11 has graduated from "preview" to actually being released, so we really should add it.

@@ -132,7 +132,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
script.type = 'text/javascript';
script.src = url;

if (msie) {
if (msie && script.onreadystatechange) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the msie part actually still required?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.

@allaud
Copy link

allaud commented Oct 22, 2013

@eddiemonge @vra @btford
This commit breaks jsonp support in IE <= 8. So the better approach (my temprorary fix in Angular source code):

var ready_state = (msie <= 8) ? true : script.onreadystatechange;

if (msie && ready_state) {

@eddiemonge
Copy link
Contributor Author

@allaud You are right. I incorrectly assumed the existence of the property would allow the if statement. However, I forgot to check what the property was actually set to. If the property is set, its initial value is null. Checking for the typeof was better then checking the value. IE11 doesn't have the property at all so it is undefined where other IE's have it as null, which is an object, not undefined.

After checking IE 7-11 (7 didnt like my angular test case at all) I have verified the updated code now runs correctly. Non-IE browsers still won't see it because of the MSIE part.

@eddiemonge
Copy link
Contributor Author

Now with a live demo: http://jsbin.com/EYuCUxi/1

@@ -132,7 +132,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
script.type = 'text/javascript';
script.src = url;

if (msie) {
if (msie && typeof script.onreadystatechange !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

if ( msie && isDefined(script.onreadystatechange) ) {

@petebacondarwin
Copy link
Contributor

Apart from using isDefined(), this LGTM.

@petebacondarwin
Copy link
Contributor

I can confirm that the problem is apparent for me on IE11 @ Angular 1.2-rc.3 and is fixed by this patch.

Moreover @btford - IE11 causes numerous other errors on grunt test so bringing in IE11 to the CI build will involve a non-trivial effort.

IE11 changed their script api and no longer uses onreadystatechange. It
now follows other browsers with onload and onerror

Fixes #4523
@caitp
Copy link
Contributor

caitp commented Nov 14, 2013

#4922 adopts a similar approach --- In the commit discussions, @mzgol references jQuery's approach' to the same problem, which circumvents the issue in a more robust manner without relying on browser sniffing. As I mention there, I don't see a reason a similar approach couldn't be leveraged here

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request Nov 22, 2013
IE8, IE9 and IE10 can use `script.onreadystate` so up till now we have been using this
if the sniffer says we are on IE.
But IE11 now does not support `script.onreadystate` and only supports the more standard
`script.onload` and `script.onerror`.
IE9 and IE10 do support `script.onload` and `script.onerror`. So now we only test whether
we are on IE8 or earlier before using `script.onreadystate`.
See http://pieisgood.org/test/script-link-events/

jQuery just uses all these handlers at once and hopes for the best, but since IE9 and IE10
support both sets of handlers, this could cause the handlers to be run more than once.

jQuery also notes that there is a potential memory leak in IE unless we remove the handlers
from the script object once they are run.  So we are doing this too, now.

Closes angular#4523
Closes angular#4527
Closes angular#4922
@eddiemonge eddiemonge deleted the issue_4523 branch November 22, 2013 16:30
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
…SONP

IE8, IE9 and IE10 can use `script.onreadystate` so up till now we have been using this
if the sniffer says we are on IE.
But IE11 now does not support `script.onreadystate` and only supports the more standard
`script.onload` and `script.onerror`.
IE9 and IE10 do support `script.onload` and `script.onerror`. So now we only test whether
we are on IE8 or earlier before using `script.onreadystate`.
See http://pieisgood.org/test/script-link-events/

jQuery just uses all these handlers at once and hopes for the best, but since IE9 and IE10
support both sets of handlers, this could cause the handlers to be run more than once.

jQuery also notes that there is a potential memory leak in IE unless we remove the handlers
from the script object once they are run.  So we are doing this too, now.

Closes angular#4523
Closes angular#4527
Closes angular#4922
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
…SONP

IE8, IE9 and IE10 can use `script.onreadystate` so up till now we have been using this
if the sniffer says we are on IE.
But IE11 now does not support `script.onreadystate` and only supports the more standard
`script.onload` and `script.onerror`.
IE9 and IE10 do support `script.onload` and `script.onerror`. So now we only test whether
we are on IE8 or earlier before using `script.onreadystate`.
See http://pieisgood.org/test/script-link-events/

jQuery just uses all these handlers at once and hopes for the best, but since IE9 and IE10
support both sets of handlers, this could cause the handlers to be run more than once.

jQuery also notes that there is a potential memory leak in IE unless we remove the handlers
from the script object once they are run.  So we are doing this too, now.

Closes angular#4523
Closes angular#4527
Closes angular#4922
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jsonp does not work in IE11. Angular 1.2 rc3
7 participants