473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

How do I read args passed in address bar?


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
Jul 23 '05 #1
2 3269
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.html" + theData;
newWindow = window.open(URLstring,"Printable",
"statusbar,menubar,resizable,toolbar,height=600,wi dth=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
Jul 23 '05 #2
Robert wrote:
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.html" + theData;
newWindow = window.open(URLstring,"Printable",
"statusbar,menubar,resizable,toolbar,height=600,wi dth=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
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I...
2
by: Pierre Fortin | last post by:
This quest for understanding started very innocently... A simple error on my part, passing on args as "args" instead of "*args" to os.path.join() led me to wonder why an error wasn't raised... ...
20
by: ncf | last post by:
Hello all, I was wondering if there was any way to pass arguments (integer and such) by reference (address of), rather than by value. Many thanks in advance. -Wes
4
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
19
by: Mark Richards | last post by:
I've been programming for many years, but have only recently taken a deep "C" dive (bad pun, i know) and need a lot of explanation from an expert. My questions center around those mysterious...
3
by: RSB | last post by:
Hi Everyone, I have this TextBox with the TextMode="MultiLine". so now it does not validate the text in the TextBox for the MaxLength SO i have decided to execute a CustomValidator for this...
1
by: jakebbohio | last post by:
I have a user-defined XPath function implemented using a custom context and the IXsltContextFunction interface. For its arguments, it accepts 3: { XPathResultType.Any, XPathResultType.Any,...
1
by: cmdolcet69 | last post by:
So I have two handlers: AddHandler dataBackgroundWorker.DoWork, AddressOf DoDualDSIWorkCOM1 AddHandler dataBackgroundWorker2.DoWork, AddressOf DoDualDSIWorkCOM1 ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.