Sending Variable through URL

I

ian.hubling

I've spent a few hours looking for an answer - it its here, I apologize
upfront. I also apologize if I don't use the correct terminology.

I have two pages - A & B. Page A is in the main window of a frameset.
On page A is a link to page B. Page B is a universal form used by many
other pages. I need a way for the referring link to identify that page
A called it.

But... Instead of using a literal text tacked onto the referring URL
such as:

<a href="page_b.htm?page_a">

I want the code to be generic enough that I call upon page A's
document.title property.

I haven't figured out how to insert the property into the URL line and
not have it come out as a literal on page B. Can someone help? Please
be specific with suggestions for both ends (ie page A and B) - I have a
hard time following some of the logic at times <grin>. If this isn't
possible because of a limitation, please let me know so that I'm not
wasting more time.

If this isn't possible - anybody have a more elegant solution to draw
from the document.title property?
 
W

web.dev

I've spent a few hours looking for an answer - it its here, I apologize
upfront. I also apologize if I don't use the correct terminology.

I have two pages - A & B. Page A is in the main window of a frameset.
On page A is a link to page B. Page B is a universal form used by many
other pages. I need a way for the referring link to identify that page
A called it.

But... Instead of using a literal text tacked onto the referring URL
such as:

<a href="page_b.htm?page_a">

I want the code to be generic enough that I call upon page A's
document.title property.

Why are you using document.title? The method you're going about will
not help you solve the problem. The document.title property only
returns you the title of the document (the text between the
<title></title> tags).

A quick solution could be the following:

Page A:
Continue to do what you're doing, tack onto the end of url:

<a href = "page_b.htm?page_a"> to page b</a>

Page B:
You should use location.search, which will give you the URL query
string. This will give you everything after and including the question
mark.
 
I

ian.hubling

There is a reason why I'd like to use the document.title property.
There are more than 2,000 pages in which we will be inserting a
standard block of replacement code - which includes the link to page B.
The document titles already exist in all the pages - so we'd like to
pick up these properties and not have to re-enter them in the URL.
 
R

RobG

There is a reason why I'd like to use the document.title property.
There are more than 2,000 pages in which we will be inserting a
standard block of replacement code - which includes the link to page B.
The document titles already exist in all the pages - so we'd like to
pick up these properties and not have to re-enter them in the URL.

Add the escaped page title to the href of the element:

<a href="z1.html"
onclick="return fwdTitle(this);">z1.html</a>

<script type="text/javascript">
function fwdTitle (el)
{
var t = encodeURIComponent(document.title);
if (el.href){
document.location = el.href + '?' + t;
return false;
}
}
</script>


On page B, get the title as:

var pTitle = decodeURIComponent(document.location.search.substr(1));


Support for encodeURIComponent/decodeURIComponent should be tested and
escape/unescape attempted as fallback.

You could add the onclick to the links dynamically onload to save coding.
 

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
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top