Detect when an iframe starts to load new URL

前端 未结 4 1909
孤街浪徒
孤街浪徒 2021-01-31 02:07

How can I detect that an iframe on my page starts to load a new page?

Our situation is:

  • When iFrame content starts to change we need to di
4条回答
  •  野的像风
    2021-01-31 02:41

    When you are creating the iframe dynamically, include the ONLOAD event like so...

    F=document.createElement('iframe');
    F.onload=function(){
        UpdateDetails(
            this.contentWindow.document.title,
            this.contentWindow.location
        );
    };
    F.src='some url';
    document.getElementById('Some_Container').appendChild(F);
    

    The onload event will now constantly update the global variables below via the function below, as the user surfs the net:

    var The_Latest_Title='';
    var The_Latest_URL='';
    function UpdateDetails(Title,URL){
        The_Latest_Title=Title;
        The_Latest_URL=URL;
    }
    

提交回复
热议问题