简体   繁体   中英

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?

I have a page that has an iframe which plays video. 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. 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.

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. I'm just not that knowledgeable in javascript.

Here is the javascript code for the full popad below:

    <!-- 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>

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