By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

simple question 2

P: n/a
Sir

I have the simple question as follows:

I got three pages a,b,c point to same page d when clicking submit.
Is there any way, by using JavaScript to trace back which page a or b or c
to reach it, once exit button is clicked on page d?

thanks
Timothy Ma
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sat, 21 Aug 2004 23:02:01 GMT, timothy ma and constance lee
<ti******@shaw.ca> wrote:
I got three pages a,b,c point to same page d when clicking submit.
Is there any way, by using JavaScript to trace back which page a or b or
c to reach it, once exit button is clicked on page d?


You can trace what page sent the value by adding a name/value pair to the
query string when you transmit the page. The value could either by a
unique string or the path/filename of the referring document.

Of course, it's not a good idea to hinge page functionality on a script;
you can apply what I'm about to say on the server, too.

Getting the value that was inserted into the query string is fairly
trivial.

var i, ref;
if((i = location.search.indexOf('name=')) != -1) {
ref = location.search.substring(i + 5, i + 5 + length);
}

Getting the correct value of 'length' depends on what values you use. If
the values are all of the same length, then it's simple. If it's a
variable string, then you'd need something like:

var i, j, ref, s = location.search;
if((i = s.indexOf('name=')) != -1) {
/* Find delimiter of next pair. If not
* found, extract up to end of string. */
if((j = s.indexOf('&', i)) == -1) {j = s.length;}
ref = s.substring(i + 5, j);
}

In either case, replace 'name' as appropriate.

I haven't tested either of the solutions above but they should work.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.