Results 1 to 3 of 3

Thread: Jump to anchor tag onload

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question Jump to anchor tag onload

    Hello all,

    I needs some help. I currently have a script to jump to an anchor tag when the page loads:

    Code:
    <script type="text/javascript">
    
    function goToAnchor() {
    location.href = "myPage.html#myAnchor";
    }
    
    </script>
    Now, I would like to take it a step further and would like to link from page A to page B that usually takes a while to load and once the page loads, run a script to jump to the specified anchor tag on the page after everything has loaded. I know I have to add some parameters at the end of the url link on page A, but that's where I get stuck.


    Can anyone please help?

  2. #2
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    Do you mean:

    HTML Code:
    <a href="http://www.yourdomain.com/pageb.html#anchor">Click me</a>
    I'm kinda confused

  3. #3
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question

    Thanks but...

    While waiting to get help, I was able to figure out a solution to using js to force a specific anchor call to jump after the page completely loads. The reason I am doing this is because the page I am linking to with anchors takes a long time to load and a standard browser anchor link sometimes does not work 100%. With that said, I would now like to make the script I wrote universal to get ANY anchor param in the url and jump to that spot on the page. Right now it's coded to just look for "#anchor". I want to re-code it so it will look for "#" + "anyAnchorName".


    Page A:
    Code:
    <a href="pageB.html#anchor">Click</a>

    Page B:
    Code:
    <script type="text/javascript">
    function load() {
    	var urllocation = location.href;
    	if(urllocation.indexOf("#anchor") > -1){
    		window.location.hash="anchor"; 
    	} else {
    	return false;
    	}
    }
    </script>
    
    
    <body onload="load()">

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
  •