|
-
Jun 3rd, 2004, 10:06 AM
#1
Thread Starter
Frenzied Member
Javascript - get the address bar arguments
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?
-
Jun 3rd, 2004, 10:17 AM
#2
Frenzied Member
Get them using a server side script, I usually do that...
<script>
var var1=<%=Request("var1")%>;
</script>
An example using ASP
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Jun 3rd, 2004, 10:48 AM
#3
Thread Starter
Frenzied Member
test.htm
PHP Code:
<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
PHP Code:
<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.
-
Jun 3rd, 2004, 12:10 PM
#4
Frenzied Member
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.
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Jun 4th, 2004, 06:36 AM
#5
In pure client-side JavaScript you need to parse the url yourself, you can get it from
location.href
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|