If my web page is referenced in the address bar, how can I read these
arguements?
Thus, with
http://www.mydomain.com/mypage.html?abc=123
Is there an easy method to read abc=123 ?
You need to look in: location.search
You may want to escape the passed data. This is commonly done.
This html file and associated Javascript passed data to a second htmls
file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Loops</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<SCRIPT type="text/javascript">
function foo()
{
var theData, newWindow, URLstring;
// Pass this data. I believe the data is limitted to a max
// of 2k.
theData = "?data=" + escape("see if the caller gets this.");
URLstring = "tryRead.ht ml" + theData;
newWindow = window.open(URL string,"Printab le",
"statusbar,menu bar,resizable,t oolbar,height=6 00,width=800");
newWindow.focus ();
}
</script>
</HEAD>
<BODY onload='
alert("before." );
foo();
alert("after.") ;'>
<br><br>Lets open a window and pass data to the window.
</BODY>
</HTML>
This html file and Javascript read the passed data:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Read passed data</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<SCRIPT type="text/javascript">
function foo2()
{
var theData;
var begin;
begin = location.search .indexOf("data= ");
if (begin >0 )
{
theData = location.search .substring(begi n+5,location.se arch.length);
theData = unescape(theDat a);
alert("theData = " + theData);
}
}
</script>
</HEAD>
<BODY onload="foo2()" >
<br><br>Read passed data.
</BODY>
</HTML>
Robert