简体   繁体   English

如果iFrame网址是google.com,则重定向到页面

[英]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 我想使用javascript,因此,如果页面网址上的iframe变为“ https://google.com.eg ”,则它必须具有功能

Function for example: 功能例如:

  • Redirect to error.php using "window.href" 使用“ window.href”重定向到error.php
  • Show javascript box saying "error" 显示JavaScript框显示“错误”

My iframe is: 我的iframe是:

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

And I want to prevent my site visitors to go to the Google homepage. 而且,我想阻止我的网站访问者访问Google主页。

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”;}}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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