Results 1 to 3 of 3

Thread: auto click using .click()

  1. #1
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question auto click using .click()

    Hey guys just need a little help.

    I need to create a little script that clicks a link automatically and opens it up in a new page.

    So far I have this:

    Code:
    <head>
    <script>
    function autoClick(){
    document.getElementById('linkToClick').click();
    }
    </head>
    <body onload="setTimeout('autoClick();',3000);">
    <a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
    </body>
    It works but the problem is that IE popup blocker keeps blocking the new window.

    Is there a way to do the same thing with javascript without it having blocked by IE popup blocker?
    [/CODE]

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    guess you are aware that .click() is IE only

    there will be a warning if you are testing locally but it should be OK(IE only) online.
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, you will need to close the script tag:

    Code:
    <head>
    <script>
    function autoClick(){
    document.getElementById('linkToClick').click();
    }
    </script>
    </head>
    <body onload="setTimeout('autoClick();',3000);">
    <a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
    </body>
    And it is IE only. Even in IE, if the pop up blocking settings are high enough, the blocker will still block it. Like, if clicking on the link is blocked (highest setting - block all pop ups), then the script won't work either.


    You really shouldn't be popping things up in a window though, there are almost always better, though often more complicated ways to accomplish whatever you are trying to do, ways that will work cross browser and not be subject to pop up blocking.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •