Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q298 How can I pass a complete absolute url from one page to another?

You are here: irt.org | FAQ | JavaScript | Link | Q298 [ previous next ]

You need to pass the url following the ? in the url to the next page, however the passed url needs to be encoded so that non alphanumeric characters are converted to hexidecimal codes. this is simply done using the JavaScript escape() method:

<script language="JavaScript"><!--
function go(newURL) {
    location.href='nextpage.html?' + escape(newURL);
}
//--></script>

<a href="javascript:go('http://www.somewhere.com/')">http://www.somwhere.com/</a>

In fact, in the first document you can avoid encoding the url, if you have already encoded it by hand:

<A HREF="nextpage.html?http%3A//www.somewhere.com/">http://www.somewhere.com/</a>

And then subsequently decoded in the nextpage.html document using the JavaScript unescape() method:

<script language="JavaScript"><!--
var newURL = unescape(location.search.substring(1));
alert(newURL);
//--></script>

Feedback on 'Q298 How can I pass a complete absolute url from one page to another?'

©2018 Martin Webb