Fun Programmer
Fun Programmer

Reputation: 1

Refresh page link clicked automatically

I would like so reference like when I enter into a page, suddenly a link should be clicked. Is it possible to perform that Tried 1

     <script>
          document.onload = function(){
           document.getElementById('overviewOfSolarSystem').click();
      }
     </script> 

Tried 2 This the code i tried but not working

     <script>
          document.onload = function(){
          document.getElementById('javascript:setPage(2)').click();
         }
     </script> 

Below is the link in the body

     <a id="overviewOfSolarSystem;" style="color:#ffbc00;" href="javascript:setPage(2)">(Learn More)</a>

Upvotes: 0

Views: 182

Answers (5)

Fun Programmer
Fun Programmer

Reputation: 1

Below is the answer for this question.

    <script type="text/javascript">
        window.location.href = "http://www.example.com"
    </script> 

Upvotes: 0

JC Hern&#225;ndez
JC Hern&#225;ndez

Reputation: 807

Pure javascript, as the question:

window.onload = function(){
   document.getElementById('overviewOfSolarSystem\\;').click();
}

If you use jQuery, the answer above's best.

EDIT: Edited my answer as you edited the question :D

Upvotes: 0

Alex M.
Alex M.

Reputation: 641

Add this just before your </body>:

<script>
    var element = document.getElementById('overviewOfSolarSystem');
    element.click()
</script>

Upvotes: 1

Stormhashe
Stormhashe

Reputation: 704

add to your html

<script>   
$(function(){
        $("#yourLinkIdHere").click();
    });
</script>

Explaining:

the $(function(){}); is an aliais for the document.ready javascript event. this code just tells javascript to click the element that has the id "yourLinkIdHere" when the page finishes loading

Upvotes: 0

Parth Raval
Parth Raval

Reputation: 4423

     //Html File
     <a class="refresh_link" href="javascript:void(0)">click to Refresh the Page</a>
        //Js Code
        $(document).ready(function() {
        $(".refresh_link").click(function() {
            window.location = "https://jsfiddle.net/";
        });
    });

Upvotes: 0

Related Questions