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

Q870 How can I pass a querystring parameter from a link to a function on the linked page?

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

If you actually want to set this value to the value of a JavaScript variable then:

<script language="JavaScript"><!--
var variableName = 'Hello world';
//--></script>

<a href="newpage.html" onClick="this.href='newpage.html?' + variableName">Linked page</a>

To retrieve it in newpage.html:

<script language="JavaScript"><!--
var variableName = null;

if (location.search.length > 0)
    variableName = location.search.substring(1);

function functionName(text) {
    alert(text);
}

functionName(variableName);
//--></script>

Feedback on 'Q870 How can I pass a querystring parameter from a link to a function on the linked page?'

©2018 Martin Webb