0

This test (to sending a cross domain AJAX or not) is always false on Internet Explorer but it works on Microsoft Edge.

It looks like, the <a> element doesn't populate on IE.

function testSameOrigin(url){
    /*
        Return true if belongs to the same origin
    */
    var loc = window.location,
        a = document.createElement('a');

    a.href = url;

    return a.hostname == loc.hostname &&
           a.port == loc.port &&
           a.protocol == loc.protocol;
}

How can I fix this?

Thanks for helping.

Jonathan Eustace
  • 2,469
  • 12
  • 31
  • 54
Acute
  • 1
  • 1

1 Answers1

0

I fix it :

function testSameOrigin(url){

        var canonicalize = function(url) {
            var div = document.createElement('div');
            div.innerHTML = "<a></a>";
            div.firstChild.href = url;
            div.innerHTML = div.innerHTML;
            return div.firstChild.href;
        };

    var loc = window.location
      , a = document.createElement('a');

    a.href = canonicalize(url);

    return a.hostname == loc.hostname &&
           ( a.port == loc.port || ((a.port == 80 || a.port == 443 ) && loc.port =="") ) &&
           a.protocol == loc.protocol;
}

This post help me to find my way.

Acute
  • 1
  • 1