简体   繁体   中英

Redirect to page if iFrame url is google.com

I want to use javascript, so if an iframe on my page's url became ' https://google.com.eg ' it must do a function

Function for example:

  • Redirect to error.php using "window.href"
  • Show javascript box saying "error"

My iframe is:

<iframe src="https://translate.google.com.eg" id="myframe"></iframe>

And I want to prevent my site visitors to go to the Google homepage.

Thanks!

在iframe加载函数中,检查document.getElementById(“ myiframe”)。contentWindow.location.href ==“ google.com”,然后继续执行回调

如果您使用的是jQuery $(document).ready(function(){ var a = $('#myiframe').attr('src'); If(a =='www.google.com'|| a = ='google.com'|| a ==' https: //google.com.eg'){window.location.href =“ error.php”;}}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM