Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a full url and query string in Javascript?

Status
Not open for further replies.

crighton

Programmer
Aug 31, 2001
7
ES
Hi,

I've hit a snag with what I thought would be a routine "send this page to a friend" link.

The email itself is sent with php, but the process begins with a javascript window launch that passes the following code to the new window:

var url = url + "?url=" + location.href

Now, my pages have urls that look like this (or at least they vary on this general structure):


The javascript clip above terminates the url after the initial query (?page=photograph), resulting in the following incomplete url being included in the final sent email:


Clicking on each of those will show you the difference.

I'd prefer - if possible - to keep the current system having already spent some hours on design with it, so my preferred solution is to find a way to pass those urls in full - queries, ampersands and all.

Anyone have any idea how I can do this?

Help appreciated...

Gary
 
Try this (basically, the escape and unescape functions are the key).

Chad.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>pass uncorrupted url</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function gothere() {
var thispage=location.href;
var url = &quot; + escape(thispage);
parent.location.href = url;
}

var myRE = /.+url\=.+/
var urlexists = myRE.exec(location.href) ? true : false;
if(urlexists) {
var thisurl = location.href.split('url=');
thisurl = unescape(thisurl[1]);
}
</script>
</head>
<body>
<script language=&quot;javascript&quot;>
if(urlexists) {
document.write(thisurl);
}
</script>
<a href=&quot;javascript:gothere();&quot;>go there</a>
</body>
</html>
ICQ: 54380631
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top