How do I read args passed in address bar?

  • Thread starter Reply Via Newsgroup
  • Start date
R

Reply Via Newsgroup

Folks,

I'm pretty sure it can be done, and I'm doing pretty good with my
javascript so I'm pretty sure I just need a quick point in the right
direction...

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 ?

Why?

I want to create a single HTML file that contains a script that will be
used to display an image in the center of the screen. This HTML file
will be used as a popup so when a user clicks on a thumbnail, the larger
image opens... I don't like the idea of having numerous html files
containing reference to each image - I'd prefer to have my parent window
call the popup and pass it arguements, like the filename and size of
the image - One advantage to this method is that I can tailor the size
of the popup window to the size of the image.

Before anybody beats me over the head for using a popup, I
1) am working on an application, not a website
2) my end users will have javascript and popups enabled
3) popups open only with an onClick event occurs on a correctly labeled
link.

All help, via the newsgroup, much appreciated... thanks,
randelld
 
R

Reply Via Newsgroup

Robert said:
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.html" + theData;
newWindow = window.open(URLstring,"Printable",
"statusbar,menubar,resizable,toolbar,height=600,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(begin+5,location.search.length);
theData = unescape(theData);
alert("theData = " + theData);
}
}
</script>

</HEAD>
<BODY onload="foo2()">

<br><br>Read passed data.

</BODY>

</HTML>

Robert

Thanks - I think I can run with that... Much appreciated,
randelld
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top