SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clicking in a Hyperlink without a name

    I have one page that contains one frame called "theframe".

    Inside this frames is this code:


    PHP Code:
    <a href="'.$generatedlink.'"><img src="'.$generatedpicture.'"></a

    And i want to force the browser to click on that generated link.
    I cant give a name to the <a> tag, so JavaScript must look for <a> and click on them.

    This code is for a game i'm doing, this is the part where the computer plays. I'm doing using this logic because its part of the game.


    Resuming: I need a Javascript code that forces the browser to click on all <a> tags he finds (or the only <a> tag the page in that iframe has).
    Dont forget that clicking on the tag is the same that redirecting the iframe (not the browser please) to the Href of that tag.


    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :'(

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    window.onload = function () {
      // click on the first <a> tag found
      document.getElementsByTagName("a")[0].click();
    
      // click on all <a> tags (not sure how/if this will work)
      var atags = document.getElementsByTagName("a");
      for (var i=0; i < atags.length; i++) {
        atags[i].click();
      }
    }
    </script>

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, GetElementsByTagName, i didnt know that one.

    Btw, its not working yet, i'm putting it this way:

    PHP Code:
    <html>

    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <
    title>New Page 1</title>

    <
    script type="text/javascript">
    window.onload = function () {
    // click on the first <a> tag found
    parent.nFrame.getElementsByTagName("a")[0].click();
    }
    </script>

    </head>

    <body>


    <center><iframe name="nFrame" src=next.php space=0 vspace=0 width=468 height=60 marginwidth=0 marginheight=0 frameborder=0 scrolling=no></iframe>
    </center>
    </body>

    </html> 

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why parent? And no ref to the document element of the iframe

    window.frames["nFrame"].document.getEle......

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser View Post
    why parent? And no ref to the document element of the iframe

    window.frames["nFrame"].document.getEle......
    I used parent on a similar script lol.


    Its not working yet.

    I created an example of a banner i got from a website.
    The banner is in a frame, the page that has the frame has the code.

    Click here to see it!

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that the iframe is in a different domain than the parent window.

    Javascript has no access to frames/popups unless they are in the same domain.

    It's a bit sneaky to be trying to automate banner clicks anyway.

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •