jquery-pjax icon indicating copy to clipboard operation
jquery-pjax copied to clipboard

fix cross origin check for ie

Open tbuechner opened this issue 10 years ago • 11 comments

in ie sometimes the link.protocol and link.hostname attributes are not set correctly, parse the href manually

tbuechner avatar May 31 '15 12:05 tbuechner

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

mislav avatar Jun 01 '15 06:06 mislav

I Can remember that jQuery also uses this "hack" to work around ie limitations, but cannot find the issue/ticket right now.

staabm avatar Jun 01 '15 06:06 staabm

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.

tbuechner avatar Jun 01 '15 06:06 tbuechner

Without a test case to reproduce it with, I can't merge this yet.

mislav avatar Jun 01 '15 07:06 mislav

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.

staabm avatar Jun 01 '15 07:06 staabm

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.

btoews avatar Jun 01 '15 15:06 btoews

Oh it's an IE thing? I will check, thanks

mislav avatar Jun 01 '15 16:06 mislav

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.

mynock avatar Jun 10 '15 00:06 mynock

Reproduced in IE11 for generated link like this:

$('<a/>', {href: '/path/...'})

Debugger shows empty protocol and hostname.

Vovan-VE avatar Apr 13 '16 03:04 Vovan-VE

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);

Vovan-VE avatar Apr 13 '16 04:04 Vovan-VE

+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.

lustremedia avatar Jun 14 '16 09:06 lustremedia