Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run a JS function from another HTML file

Status
Not open for further replies.

flashbbeb

MIS
Mar 29, 2005
106
US
Hi all,

I have a page that includes a JS-based tabbed menu. From another page, I want to be able to 1) launch the menu'd page and 2) take the user right to a tab (that isn't the default).

The launch the page part is HTML 101 href stuff, but how do I get the link to run "step 2" when the launched page loads?

I've tried this with onclick AND onload to no avail:

<a href=" onclick="tabview_switch('TabView', 2);" target="_blank">click here</a>

Thanks!
EB
 
You cannot use embedded JS from another page in an HTML like that. The only way would be to someone parse the HTML file and use eval() on the results. This is just a nasty solution.

Why not put the JS into an external JS file? Then both pages can use the JS needed.
 
Hi

Define "to no avail". Nothing happens ? Something may happen but no idea what because never ends ? Something happens but not what you expected ? Happens what you expected but something else also happens which destroys the result ? An error occurs ?

Anyway, is hard to solve it without seeing the page(s) or at least to know what kind of tabbed menu script are you using.

Feherke.
 
Thanks to both of you for quick responses -

"to no avail" - the page loaded, but the tab change did not occur on that page after loading.

It may not help that I'm testing locally.

 
I suggest you set a cookie when you click the tab, and have the page that opens interrogate the cookie value to determine which menu tab to hilight when you the page loads. This can be done server-side (ideally) or client-side (using javascript).

You could use a similar technique by setting the information as a param in the URL (a GET request). This will require unravelling the location.search property instead of using cookies. The URLs can also be indexed this way.

Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top