Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 保护iframe免受其他';s并为iframe使用一个域?_Javascript_Url_Iframe_Redirect_Save - Fatal编程技术网

Javascript 保护iframe免受其他';s并为iframe使用一个域?

Javascript 保护iframe免受其他';s并为iframe使用一个域?,javascript,url,iframe,redirect,save,Javascript,Url,Iframe,Redirect,Save,嗨,我想用java脚本来保护Iframe,它们只在一个站点上工作,就像 iframe站点url是www.iframe.com,我想在www.my-mainwebsite.com 我只希望www.iframe.com仅在www.my-mainwebsite.com上工作,当这些iframe代码使用另一个站点,如www.anothersite.com时,它们将重定向到www.my-mainwebsite.com <script type="text/javascript"> if (to

嗨,我想用java脚本来保护Iframe,它们只在一个站点上工作,就像 iframe站点url是www.iframe.com,我想在www.my-mainwebsite.com

我只希望www.iframe.com仅在www.my-mainwebsite.com上工作,当这些iframe代码使用另一个站点,如www.anothersite.com时,它们将重定向到www.my-mainwebsite.com

<script type="text/javascript">
if (top !=self || top.location != "www.iframe.com") {
   top.location=self.location;
}
</script>
if(top!=self | | top.location!=“www.iframe.com”){ top.location=self.location; }
如果您想确保没有人能够在IFrame中显示您的网站,可以使用下面的快速JavaScript代码

Edit1:

  • 如果站点不等于“www.iframe.com”,则添加了第二次签入

谢谢,但我希望有一个网站能够使用这个iframe,而不是其他更新的代码,没有时间进行测试,通常它应该正常工作,可以重新表述你的问题吗?因为我认为我当时没有真正理解你的意思(:@Mr.Zijkant:那不是
&
而不是
|