/    Sign up×
Community /Pin to ProfileBookmark

How do I use javascript to tell me which link brought me to my current page?

Hi,

I have a home page with basic links to anchored sections of a second page.

On the second page i have some content which contains a variety of functions that will run depending on which link the user clicked from the home page.

My question is what javascript can I use on the second page which will identify the link used from the home page.

Thank you

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@tirnaAug 09.2010 — One way to do it is to attach a query string with a unique value to the link's href url and then check on the second page what the value is. Then do whatever you need to do depending on what the value is.
Copy linkTweet thisAlerts:
@gregcauthorAug 09.2010 — Thank you for you quick response ?

Could you perhaps give me some example code as I am not very skilled yet.
Copy linkTweet thisAlerts:
@tirnaAug 09.2010 — The code depends on whether you are using javascript or a server side script.

If you Google something like "parse query string javascript" you will get lots of examples on the www on how to do it client-side..
Copy linkTweet thisAlerts:
@gregcauthorAug 10.2010 — Thanks for your advice - think i'm getting somewhere now! ?
Copy linkTweet thisAlerts:
@Sterling_IsfineAug 10.2010 — If you're linking to anchors, all you need is to read [I]location.hash[/I].
×

Success!

Help @gregc 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 5.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...