Iframe Src Change Event Detection

iFrame src change event detection?

You may want to use the onLoad event, as in the following example:

<iframe src="http://www.google.com/" onLoad="alert('Test');"></iframe>

The alert will pop-up whenever the location within the iframe changes. It works in all modern browsers, but may not work in some very older browsers like IE5 and early Opera. (Source)

If the iframe is showing a page within the same domain of the parent, you would be able to access the location with contentWindow.location, as in the following example:

<iframe src="/test.html" onLoad="alert(this.contentWindow.location);"></iframe>

How can I detect an IFrame changing src using JavaScript

You can use "onload" event on iframe tag to detect iframe src change, when src is changed new page is loaded in iframe and "onload" event is triggered.

you can also use on "onhashchange" event to detect hash changes as well.

Detecting src/location change in a iframe object

Use correct case in "ContentWindow", it's supposed to be "contentWindow".

<iframe src="your initial URL" onload="alert(this.contentWindow.location.href)" /> 

works.

Detect when an iframe starts to load new URL

I found a better solution if iframe and the container page is same origin, don't have to put extra code into the inner page:

<iframe src="same-origin.com" onload="content_finished_loading(this)"></iframe>
<script>
var indicator = document.querySelector('.loading-indicator');
var content_start_loading = function() {
indicator.style.display = 'block';
};

var content_finished_loading = function(iframe) {
indicator.style.display = 'none';
// inject the start loading handler when content finished loading
iframe.contentWindow.onunload = content_start_loading;
};
</script>

How to detection iframe URL jump to another URL

You can try to use $_SERVER ['HTTP_REFERER'] to get the refresh page url, if the value is undefined or null, it is accessed directly.

how to detect when an Iframe change location without onload event and trigger a function?

i figure out how to do the functionality i was seeking for with help from here:
How can I get Iframe event before load?
this is my final code that kind of hi-jack the links to get the functionality

 $('a[target="contenido"]').bind('click', function () {
activateNavBar($(this).attr("href"));
});
function bindFunctionToLinks() {
$("#cont").contents().find('a[target = "contenido"]').bind("click", function () {
activateNavBar($(this).attr("href"));
});
}


Related Topics



Leave a reply



Submit