1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Click() inside IFRAME

Discussion in 'HTML & JavaScript' started by neue81, Apr 1, 2010.

  1. neue81

    neue81 Newbie

    Joined:
    Jan 2, 2010
    Messages:
    3
    Likes Received:
    0
    The pussys at DP say that it isn't possible to use the javascript click() function to click inside an IFRAME.

    What I want is simple, I load the ad on the iframe and after a given time it will be clicked by click().

    If someone knows how to get this working and is willing to share, you get a friend with a large network of websites for life.
     
  2. 195471

    195471 Regular Member

    Joined:
    Oct 11, 2008
    Messages:
    417
    Likes Received:
    260
    I don't know if what the DP people are saying is true, but I believe that what I've shown below accomplishes the same thing. To set this up, you need two domains to be safe. That is, if you care about faking your referrer.

    1) DomainWithYourAd.com --> this domain will have the iframe that shows your ad; for this example, I've used a 300x250 banner
    2) YourReferringDomain.com --> this domain will be the fake referrer

    Sample Code

    DomainWithYourAd.com/somepage.html

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <iframe src="http://DomainWithYourAd.com/[COLOR="Cyan"]iframesrc1.html[/COLOR]" id="banner" width="300" height="250" frameBorder="0" scrolling="no"></iframe>
    <script type="text/javascript">
    // This function resets the iframe's src attribute after 10 seconds; adjust the time to your liking
    function showBanner() {
      setTimeout ("resetIfrSrc()", 10000); // time in milliseconds --> 10000 milliseconds = 10 seconds
    }
    
    function resetIfrSrc () {
      var ifr = document.getElementById("banner");
      ifr.src = "http://YourReferringDomain.com/[COLOR="Magenta"]anotherpage.html[/COLOR]"; // this is a URL that you own and that you want as the HTTP_REFERER 
    }
    window.onload = showBanner;
    </script>
    </body>
    </html>
    
    The iframesrc1.html is a page on the first domain (DomainWithYourAd.com) that is simply a page with nothing on it except your banner, which links to anotherpage.html (the URL that you want to be seen as the referrer). This page will be seen as the referrer because of the automatic form submission via javascript on anotherpage.html.

    Code for iframesrc1.html:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <!--<base target="_blank" />-->
    </head>
    <body style="margin:0;">
    <a href="http://YourReferringDomain.com/[COLOR="Magenta"]anotherpage.html[/COLOR]"><img src="images/300250.gif" alt="" border="0" /></a>
    </body>
    </html>
    
    You can uncomment the <base target="_blank" /> if you want the URL to open in a new window in case the user clicks on your banner before they get redirected. If you leave it commented out, and the user clicks, they will go directly to anotherpage.html in the parent window (because anotherpage.html has a frame buster script). The <body style="margin:0;"> is important because it eliminates any whitespace around the left and top margins of the banner so that it will fit nicely within the dimensions of the iframe.

    Now what we need to do is set up anotherpage.html. The code for that is:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <!-- frame buster -->
    <script language="javascript" type="text/javascript">
    <!--
      if (top.frames.length!=0)
       top.location=self.document.location;
    // -->
    </script>
    </head>
    <body>
    <form id="form1" runat="server" method="post" action="[COLOR="Orange"]http://www.someoffer.com[/COLOR]"> <!-- your destination/affiliate URL -->
        <script language="javascript" type="text/javascript">
            document.getElementById('form1').submit();
        </script>
    </form>
    </body>
    </html>
    
    The frame buster script is very important because it ensures that the page that loads your iframe doesn't end up opening your destination URL inside the iframe. (I'm assuming that you want the user to actually be sent to the page that's associated with your ad, as opposed to merely simulating a click.)

    If you want to verify that hxxp://YourReferringDomain.com/anotherpage.html will be the referrer, you can do so by replacing hxxp://www.someoffer.com with hxxp://SomeDomainThatYouOwn.com/httpref.php and put the following code in httpref.php:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <meta name="robots" content="noindex" />
    </head>
    
    <body>
    <p>Referrer:</p>
    <br />
    <?php
    echo $_SERVER['HTTP_REFERER'];
    ?>
    </body>
    </html>