/    Sign up×
Community /Pin to ProfileBookmark

Javascript link + run function on page load

Hi,

I have a page (“treatments.htm”) which calls calls various functions when buttons are pressed.
For instance, when the page loads, using the innerHTML property the funtion “treatmentsIntro()” is called using <body onLoad=”treatmentsIntro()”>.

This displays text & on the page between in the <div id=”outputTreatments”>

</div> tags.

Now wehn I click on one of my buttons on the page, other functions are called, which display different images & texts between the <div id=”outputTreatments”> tags. So far so good.

What I am now trying to do is create links on my site map page not only to the treatments.htm page, but also to the effect that when I click on the “price list” link, then the user is taken to the “treatmenst.htm” page and the function “createTable()” is called on body onload so that the price list is displayed rather straight away rather than the “treatmenstIntro()” function.

I am using the following test page:
<html>
<head>
<title>JavaScript location link test</title>
</head>
<body>
<a href=”javascript:location=’treatments.htm’;>Show me the money!</a>
</body>
</html>

Is there a way of making this link automatically call the “createTable()”function when the page loads?

Thanks
LF

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@xelawhoSep 18.2011 — you can create a query string, so that the link would be like this for example:

<a href="javascript:location='treatments.htm?Price';>Show me the money!</a>

and then in your treatments page have an onload function that looks at that query string and decides what to do based on what it finds, which would look something like this:

[CODE]
function initialize() {
var torun = self.location.search.slice(1);
if (torun==Price) {
createTable();
} else {
treatmenstIntro();
}
[/CODE]


that way, if the user enters the page from anywhere else, they will get the treatmenstIntro() function first.

of course, you can make separate query strings for every link on your page and have all sorts of combinations going on.

I hope I understood your question, and that the answer is of some use.
Copy linkTweet thisAlerts:
@LutinFouauthorSep 19.2011 — Thanks for your help. This has worked.

Thanks again!

LF
×

Success!

Help @LutinFou spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...