PDA

Click to See Complete Forum and Search --> : Javascript - get the address bar arguments


wey97
Jun 3rd, 2004, 10:06 AM
Is there a way in Javascript to get the arguments passed to the url from the address bar?

If I have a page test.htm and I open it like test.htm?id=99&name=user

is there a way to get the id and name arguments?

vbNeo
Jun 3rd, 2004, 10:17 AM
Get them using a server side script, I usually do that...

<script>
var var1=<%=Request("var1")%>;
</script>

An example using ASP

wey97
Jun 3rd, 2004, 10:48 AM
test.htm


<HTML>
<HEAD>
<TITLE>Popup Example</TITLE>

<SCRIPT>

function ButtonClick()
{
window.open('temp.htm?id=345', null, null);
}
</SCRIPT>
</HEAD>

<BODY>
<BUTTON onclick="ButtonClick()">Open Window</BUTTON>
</BODY>
</HTML>


temp.htm


<HTML>
<HEAD>
<TITLE>Popup Example</TITLE>

<SCRIPT>
function GetId()
{
var var1= <% Request("id") %>;
alert(var1);
}
</SCRIPT>

</HEAD>

<BODY>

</BODY>
</HTML>


I get a Syntax error on line 7 when temp.htm pops up.

vbNeo
Jun 3rd, 2004, 12:10 PM
you need = after the <% sign, and the file needs to be renamed to .asp, furthermore does the server you run it from have to support ASP.

CornedBee
Jun 4th, 2004, 06:36 AM
In pure client-side JavaScript you need to parse the url yourself, you can get it from
location.href