jquery-pjax
jquery-pjax copied to clipboard
fix cross origin check for ie
in ie sometimes the link.protocol and link.hostname attributes are not set correctly, parse the href manually
Thanks for reporting. If the protocol and hostname aren't properly set, how is re-parsing them using the HTMLAnchorElement going to help set them? Do you have a case in which we can reproduce this?
/cc @mastahyeti
I Can remember that jQuery also uses this "hack" to work around ie limitations, but cannot find the issue/ticket right now.
Unfortunately I cannot provide you with an example. The problem occured on some links in our application, which were dynamically generated. The re-parse then happens on a newly created link, this fixed the issue in our case.
Without a test case to reproduce it with, I can't merge this yet.
just found the jquery issue/ticket which I was refereing to above: https://github.com/jquery/jquery/pull/1880
this ticket was about simplifying their URL parsing... they didn't change it because of x-browser issues. so as @mislav said, as long as we don't have something to reproduce it wouldn't make much sense to land this PR.
Yep, this sounds rights. IE returns empty hostname and protocol for anchor tags whose href is a relative path, but setting a.href = a.href works around this behavior.
Oh it's an IE thing? I will check, thanks
Just experienced this issue (IE only) and the fix in the PR solved it for us. It was happening when loading in content dynamically via AJAX and then changing the href of the new DOM elements. There's probably a simpler repro use case, but that was ours.
Reproduced in IE11 for generated link like this:
$('<a/>', {href: '/path/...'})
Debugger shows empty protocol and hostname.
IE11
var a = document.createElement('a');
a.href = '/path';
// "", "", "http://host/path"
console.log(a.protocol, a.hostname, a.href);
a.href = a.href;
// "http:", "host", "http://host/path"
console.log(a.protocol, a.hostname, a.href);
+1 I have had this issue with a widget where links are exchanged dynamically. After the href has been exchanged, a click on this link does a full reload of the page under IE11. The changes of this pull request fixes that issue.