Html link to new url and fire js function

Associate
Joined
15 Feb 2011
Posts
11
Hi
I have a link on a page that I use to direct the browser to another page no problem. However it is not just a URL link but also you could say a named anchor link since I want this particular link to open the relavent page and also display a div that is previously set to display:none and opened via a js function.
Does anyone know the right code to acheive this?

On another page i already acheive a similar thing but instead of firing a js function to display the div, I am using a named anchor within scrolling divs (jquery effect) to open the desired page and slide accross the desired div eg:
Code:
<a href="nextpage.html" onclick="location ='nextpage.html#div2'" class="panel">philosophy</a>
I have tried all kinds of combinations for the hidden div but cannot trigger the js when the browser moves to the other page.
If theres another way to move to the next page and change the style of the div to display:inline, or whatever I dont mind.
Any help will be much appreciated.
THANKS
 
Thanks for that Spunkey. I tried it and played around with it but its just not firing the js function. I think you understood right. I want the hidden div to open up (i.e. display:block)as soon as the browser moves to the url pointed in the a href.
In your code I can't see where the function references the div to be opened/unhidden.
I'm not familiar with the "window.location" code so I guess the .hash bit also picks up whatever div follows the hash in the href line?? A named anchor in effect...is that right?
Still ...sadly I can't get it to trigger the function and display the div.
Isn't there a way to call the js function from the href line?
 
Thanks again.
Your explanation is very clear and useful ...THANKS for being that way.
However I still cant make it work.
I am using jquery for other functions so it IS already included but I am using
jquery-1.3.2.min.js .However I have tried the jquery version you suggest and still no joy.
I have checked and checked again but seem to have copied your code exactly.
Forgive my ignorance but I'm bothered by the $(function() part of your code. Don't we need to give the function a name and make a call to its name ??
Really appreciate your time and help here.
 
HEY HEY!
I have it working now !! I guess you could put it down to just being a newbie !!
Since i got it working it seems to work okay in all sorts of combinations now.
I think my first error was to place the js in an external file but for some other reason it didn't work so then I placed it inline but placed in page1 (where the link is) instead of inline in page2 (where the hidden div is) So moving the js to page2 got it working. I then realised that I COULD place the script in an external file and can also work it with my version of jquery (i.e. -1.3.2.min.js).
It also works with this line of code which is close to what I had in the begining:
Code:
<a href="websites.html" onclick="location ='websites.html#portfolio'" class="panel">portfolio</a>
What I'd like you to know is that I have learned some more about the use of "hash" thanks to Spunkeys posting and just want to say a BIG THANKS to both of you for taking the time and interest. Its great that you are willing to share your knowledge and help the lesser experienced. MANY THANKS !
 
Back
Top Bottom