simple question 2

  • Thread starter timothy ma and constance lee
  • Start date
T

timothy ma and constance lee

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
 
M

Michael Winter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top