How to determine if the location of the iframe has changed?

前端 未结 2 1357
轮回少年
轮回少年 2021-01-25 03:45

I have got an iframe that displays a form from an external site,once the form is submitted it is redirected to another page that has got a thankyou message.Is it posiible to kno

相关标签:
2条回答
  • 2021-01-25 03:56
    function chkCounter(counterValue) {
           var tmp=document.getElementById('txtCounter').value;
           document.getElementById('txtCounter').value=tmp+counterValue;
    
           if(document.getElementById('txtCounter').value>1)
           {
            document.getElementById("btnClose").disabled = false;
           }
        }
    
    <input align="middle" type="button" onClick="self.close();" value="CLOSE" disabled="true" id="btnClose">
    <input type="hidden" id="txtCounter">
    
    0 讨论(0)
  • 2021-01-25 04:02

    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 has changed. The only problem with this technique is that it may not work with some older browsers like IE5 and early Opera. (Source)

    UPDATE:

    Further to your edit, you are getting the "Access Denied" error because you cannot access the contentWindow.location of a website that is not within the same domain of the parent window. While this is unfortunate for your genuine requirement, this is considered a security restriction to prevent cross-site scripting.

    0 讨论(0)
提交回复
热议问题