简体   繁体   English

阻止iframe点击输入url Javascript

[英]Preventing Iframe clicks from entering url Javascript

If anyone has a script that prevents clicks on iframe from entering a new website on mobile and laptop devices? 如果有人有一个脚本阻止iframe上的点击进入移动和笔记本电脑设备上的新网站?

I have a page that has an iframe which plays video. 我有一个页面,其中包含播放视频的iframe。 Originally when a user clicks the video's full screen mode it pops up into the site that is hosted on the video and then the user goes into that site. 最初当用户点击视频的全屏模式时,它会弹出到视频上托管的网站,然后用户进入该网站。 I never really wanted this but a week ago I placed a popad onto the page for revenue. 我从来没有真正想过这个,但一周前我在页面上放了一个popad来获取收入。 When I did this I noticed that users no longer go through to the other site when the iframe video is double clicked on full screen, in fact it prevents full screen from happening completely. 当我这样做时,我注意到当全屏双击iframe视频时,用户不再访问其他网站,实际上它会阻止全屏完全发生。

I no longer want the popad on the page but I'd like to rip apart the code and find out what in the code is preventing the iframe to pop up. 我不再需要页面上的popad,但我想撕掉代码并找出代码中阻止iframe弹出的内容。 I'm just not that knowledgeable in javascript. 我只是不懂javascript知识。

Here is the javascript code for the full popad below: 以下是完整popad的javascript代码:

    <!-- PopAds.net Popunder Code -->
<script type="text/javascript" data-cfasync="false">
/*<![CDATA[/* */
  var _pop = _pop || [];
  _pop.push([' . "'siteId'" . ', 1234567]);
  _pop.push([' . "'minBid'" . ', 0]);
  _pop.push([' . "'popundersPerIP'" . ', 0]);
  _pop.push([' . "'delayBetween'" . ', 0]);
  _pop.push([' . "'default'" . ', false]);
  _pop.push([' . "'defaultPerDay'" . ', 0]);
  _pop.push([' . "'topmostLayer'" . ', false]);
  (function() {
    var pa = document.createElement(' . "'script'" . '); pa.type = ' . "'text/javascript'" . '; pa.async = true;
    var s = document.getElementsByTagName(' . "'script'" . ')[0]; 
    pa.src = ' . "'//c1.popads.net/pop.js'" . ';
    pa.onerror = function() {
      var sa = document.createElement(' . "'script'" . '); sa.type = ' . "'text/javascript'" . '; sa.async = true;
      sa.src = ' . "'//c2.popads.net/pop.js'" . ';
      s.parentNode.insertBefore(sa, s);
    };
    s.parentNode.insertBefore(pa, s);
  })();
/*]]>/* */
</script>
<!-- PopAds.net Popunder Code End -->

You can see the code below. 你可以看到下面的代码。 It is opening the pages in same tab and if the url doesnt contain your website name then it does not open it and opens the page that you specify. 它在同一个选项卡中打开页面,如果网址不包含您的网站名称,则它不会打开它并打开您指定的页面。 I hope it helps! 我希望它有所帮助!

<html>
<head>
<script type="text/javascript">
function navigate(url)
{
    var iframe = document.getElementsByTagName( "iframe" )[0];
    if(url.indexOf("yorkshirepost")>=0){
     iframe.src = url;}
    else{ 
     iframe.src="http://www.yorkshirepost.co.uk/";}
}
</script>
</head>

<body>

<a href="javascript:navigate('http://www.yorkshirepost.co.uk/')">News1</a>
<a href="javascript:navigate('http://www.foxsports.com/soccer/')">News2</a>



<iframe name="main_frame" scrolling="yes" height="100%" width="100%" src="http://www.yorkshirepost.co.uk/"></iframe>

</body>
</html>

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

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