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

Sending Variable through URL

P: n/a
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?

Jan 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

ia*********@fin.gov.on.ca wrote:
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.

Jan 12 '06 #2

P: n/a
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.

Jan 13 '06 #3

P: n/a
ia*********@fin.gov.on.ca wrote:
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.

--
Rob
Jan 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.