views:

30

answers:

2

I have been trying to locate an example of remote Javascript execution from a local HTML 'a' tag. This is not going to be a malicious execution. On my index page, I use Javascript to hide divs and bring a single div to the front - in order to have multiple pages on one (in a nutshell). I typically do this using the following example snippet:

<a href="javascript:footerAbout()">About Us</a>

However, on a different PHP/HTML page on the same site, I would like to have links that will execute the Javascript in the same fashion, only after pushing the browser to the new HTTP request. For example, in my inept-thinking, I would expect it to work like this:

<a href="http://samedomain.com:javascript:footerAbout()"&gt;About Us</a>

This was a failure - as my Firefox renders the hyperlink as plaintext, and not clickable. I've scoured Google and this site for info, but found no examples. I would appreciate any feedback.

Thanks.

A: 

My understanding is that you want to invoke the same JavaScript function in multiple pages. How about using the script src tag as follows:

<script src="../common.js"></script>

I believe the src attribute can be a remote js file, but haven't tested it out.

Therefore, no matter what page you want to use the JavaScript to show the about us footer, you can have the same link:

<a href="javascript:footerAbout()">About Us</a>
URLParser.com
Hmm, I guess I did not make it clear. I have multiple links on the index page in a footer: About Us, Legal, Contact Us, etc. (and each of these have a corresponding div layer, defaulted to a 'hidden' CSS status)All of these have an individual Javascript function that makes the individual div layer to visible. On a secondary page, I wanted a footer that had the same links, but the URL would would link back to the index page, and then execute the Javascript function, depending on which link was clicked (About Us, Contact Us, etc). Thanks for your feedback - I hope that clarifies =)
Josh
A: 

So... you want to have the browser navigate to http://samedomain.com and then execute javascript:footerAbout()?

How about passing an argument as part of the address? Something to the effect of:

http://samedomain.com&amp;show=footerAbout

http://samedomain.com#footerAbout

Then reading the URL in your destination page and letting the destination execute footerAbout()?

STW