I have an iframe and using
var isInSameDomain = (window.location.host == window.parent.location.host);
I can detect if the iframe is outside my website. or using an index of my site in an array.
But it always returns false. Because the iframe's src doesn't actually change when I don't modify the src directly.
Basically I have an iframe that goes to a local page with a link on it. When I click that link the iframe goes to that page. But when I retrieve the iframe's src it still gives me the local page's url rather than the page I clicked to. When I reload the iframe manually triggering the function I have set on load it still returns the src of the last page.
$(page).load(function(){
console.log(page);
handlePage();
});
function handlePage() {
if(isUserOutside() == false) {
$(backButton).attr('class','disabled');
} else {
$(backButton).attr('class','');
}
}
function isUserOutside() {
/*for(var i = 0; i < pages.length; i++) {
var _page = pages[i];
if(canonicalize(_page) == _browser.src) {
return false
break;
}
}
return true;*/ //The old code is in comments.
return window.location.host != window.parent.location.host;
}
A good example would be this