Detect when an iframe starts loading a new url


Philip:

How can I detect that an iframe on a page starts loading a new page?

Our situation is:

  • When the iFrame content starts changing, we need to show the "loading" animation and hide the search box.
  • I know how to handle the "iframe has finished loading" event (to hide the animation), but don't know how to capture the initial "begin change" event...

Note: I can attach a jquery "click" hook to the link on the menu and it will work. However, in the iframe content, there are many cross-reference links and the "change" event works on them too! So when the user clicks a link inside the iframe or changes the iframe src via JavaScript , we need to catch the event - as we also want to show the loading animation and hide the search box.

Bruce:

If the iframe and the container page are from the same origin, I found a better solution without having to put extra code in 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>

Related


Detect when an iframe starts loading a new url

Philip: How can I detect that an iframe on a page starts loading a new page? Our situation is: When the iFrame content starts changing, we need to show the "loading" animation and hide the search box. I know how to handle the "iframe has finished loading" even

Detect when an iframe starts loading a new url

Philip: How can I detect that an iframe on a page starts loading a new page? Our situation is: When the iFrame content starts changing, we need to show the "loading" animation and hide the search box. I know how to handle the "iframe has finished loading" even

Detect loading of iframe in Chrome when downloading file

Merlin I am using a hidden iframe in an HTML page for download. I would like to know when it will be done. I've searched a lot on the internet and everyone says I should use the iframe's onloadevent handler, but it doesn't work in Chrome! I'm not sure where, b

Detect loading of iframe in Chrome when downloading file

Merlin I am using a hidden iframe in an HTML page for download. I would like to know when it will be done. I've searched a lot on the internet and everyone says I should use the iframe's onloadevent handler, but it doesn't work in Chrome! I'm not sure where, b

How to detect when a new process starts?

username I want to show that a new process ( MessageBoxif any) (not a specific program) is running. E.g: any program has been run When running any program, the MessageBoxdisplay is as follows:New process! How to do it? Sorry for the lack of detail in this ques

Change url when loading from iframe

Ebin I have the following 3 pages form123.html ........... iframe form.php .................php code validate.php .............Validating php code In my form123.html page, with iframe loaded from form.php, now the url is http://www.ect.com/form123.html <iframe

Change url when loading from iframe

Ebin I have the following 3 pages form123.html ........... iframe form.php .................php code validate.php .............Validating php code In my form123.html page, with iframe loaded from form.php, now the url is http://www.ect.com/form123.html <iframe

How to get notified when WebView starts loading a new page?

SIMMORSAL I know how to get notified when a web page is finished loading, but is there any way to know when to start loading a new web page launched from a link from the original web page? The reason I want it is ProgressBarto make it visible whenever the page

How to get notified when WebView starts loading a new page?

SIMMORSAL I know how to get notified when a web page is finished loading, but is there any way to know when to start loading a new web page launched from a link from the original web page? The reason I want it is ProgressBarto make it visible whenever the page

How to get notified when WebView starts loading a new page?

SIMMORSAL I know how to get notified when a web page is finished loading, but is there any way to know when to start loading a new web page launched from a link from the original web page? The reason I want it is ProgressBarto make it visible whenever the page

How to get notified when WebView starts loading a new page?

SIMMORSAL I know how to get notified when a web page is finished loading, but is there any way to know when to start loading a new web page launched from a link from the original web page? The reason I want it is ProgressBarto make it visible whenever the page

iframe print not working in Chrome when url starts with https

Raj I need to print the page without using window.open and window.print functions. I achieved the same using the code below. This works if the url doesn't start with https (at least what I thought). If the url starts with https, chrome prints out a blank page.

iframe print not working in Chrome when url starts with https

Raj I need to print the page without using window.open and window.print functions. I achieved the same using the code below. This works if the url doesn't start with https (at least what I thought). If the url starts with https, chrome prints out a blank page.

iframe print not working in Chrome when url starts with https

Raj I need to print the page without using window.open and window.print functions. I achieved the same using the code below. This works if the url doesn't start with https (at least what I thought). If the url starts with https, chrome prints out a blank page.

iframe print not working in Chrome when url starts with https

Raj I need to print the page without using window.open and window.print functions. I achieved the same using the code below. This works if the url doesn't start with https (at least what I thought). If the url starts with https, chrome prints out a blank page.

Detect if a new page is loading

Fczbkk Is there a way to detect through JavaScript if a new page is being loaded. Let me give an example. Another page is loading after I'm on this link: <a href='http://google.com/'>Click here</a> After clicking here, no page loads: <a href='#anchor'>Click h

Webview stuck when loading new URL

Daniel Moreno When loading a new URL with loadUrl(), the title changes and it seems like a new web page is being loaded, but the view is stuck, I can see how the scrollbars move and how the zoom controller works, but the view just freezes. This only happens wh

Collapse without toggle when loading new iframe into javascript

I gave I have two links - each of which should load a separate HTML file into an iframe. They will be loaded into the same javascript collapsed area. I want each link to load the specified file into an iframe when clicked. My problem is that if an html file is

Collapse without toggle when loading new iframe into javascript

I gave I have two links - each of which should load a separate HTML file into an iframe. They will be loaded into the same javascript collapsed area. I want each link to load the specified file into an iframe when clicked. My problem is that if an html file is

Detect when an iframe is displayed

vtloc Currently, my website is being embedded in another website. But the problem is I want to know when my iframe is displayed so I can execute some script. Similar to the following: <div id="wrapper"> <iframe id="page1"> <!-- MY PAGE 1 CODE GOES HER

Detect when an iframe is displayed

vtloc Currently, my website is being embedded in another website. But the problem is I want to know when my iframe is displayed so I can execute some script. Similar to the following: <div id="wrapper"> <iframe id="page1"> <!-- MY PAGE 1 CODE GOES HER

Detect when an iframe is displayed

vtloc Currently, my website is being embedded in another website. But the problem is I want to know when my iframe is displayed so I can execute some script. Similar to the following: <div id="wrapper"> <iframe id="page1"> <!-- MY PAGE 1 CODE GOES HER

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

Detect access denied to iframe url

winter I'm trying to check the url of an iframe, but I just realized that I don't need the actual url, just the information if the url is within my own domain. I think I can use document.getElementById("frameid").documentWindow.location.href It will return an

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the complete new src url whenever

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

iframe src URL not loading correctly

User 3011968 I have developed an online payment gateway which is usually loaded in an iframe. Now the iframe src is not loaded into its cPanel environment (Linux server). I checked the Firewall Deny IP section, but the IP is not blacklisted by the server. Any

How to detect when an iFrame is fullscreen?

near-point I have a document embedded in my website using iFrames. iFrame is from Box.com Document Viewer. iFrames have their own built-in fullscreen button. The fullscreen button is in an iFrame, so I can't attach a click event listener to the button. I added