1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Body onLoad Click link

Discussion in 'JavaScript' started by azylka, Dec 23, 2009.

  1. #1
    Hi guys. I have a quick question. What's the code for having a link with the id "autoid" clicked when the body of my html code loads?

    Thanks,
    Alex
     
    azylka, Dec 23, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    I didn't understand the question!!!
     
    s_ruben, Dec 23, 2009 IP
  3. azylka

    azylka Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Basically, I have link on my page. I want to use the click function of JavaScript to automatically click it when the page loads. The id of the link is 'autoid'.
     
    azylka, Dec 23, 2009 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    You can use this

    
    <html>
    
    <head>
    
    <script>
    window.onload = function(){
      document.getElementById("autoid").click();
    }
    </script>
    
    </head>
    
    <body>
    
    <a href="http://rubensargsyan.com" id="autoid">Ruben Sargsyan's personal website</a>
    
    </body>
    
    </html>
    
    Code (markup):
    but it doesn't work on firefox. Or you can use this:

    
    <html>
    
    <head>
    
    <script>
    window.onload = function(){
       location.href = document.getElementById("autoid");
    }
    </script>
    
    </head>
    
    <body>
    
    <a href="http://rubensargsyan.com" id="autoid">Ruben Sargsyan's personal website</a>
    
    </body>
    
    </html>
    
    Code (markup):
     
    s_ruben, Dec 24, 2009 IP
  5. brueckner

    brueckner Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    this javascript code is very good.
    but how can i set a timer. i mean when site is loading, where i have place that code, the code is clicking on the link button. that is some bit bad. i want that the code clicking to the button link after 5 seconds when site is complete loading.
    any ideas???
     
    brueckner, Jun 19, 2011 IP
  6. vitalytis

    vitalytis Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    window.setTimeout('clickit()',5000);
    function clickit(){
       location.href = document.getElementById("autoid");
    }
    HTML:
    This should work :)
     
    vitalytis, Jul 2, 2011 IP
  7. vruvishal

    vruvishal Member

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #7
    Hi,

    I agree with above codding solution. But in place of timer. U can use
    window.onload=functionName;
    it is too better than javascript timer function.


    Vishal
     
    vruvishal, Jul 4, 2011 IP
  8. idzeshan

    idzeshan Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #8
    Hello i found a website for this
    http://www.oklearncode.com/get-onload-click-link-automatically-script/
     
    idzeshan, Mar 19, 2015 IP
  9. Rohitash Jhunjhunwala

    Rohitash Jhunjhunwala Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #9
    please ask question in well manner.
     
    Rohitash Jhunjhunwala, Aug 19, 2017 IP