Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Link | Q298 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.