Passing paramiter to new window & use of it

P

P.L. Owens

I am trying to open a pop-up window with its own htm code, in order to show
an enlargement of a thumbnail. But I am passing a query string after the? in
the url of the new window. for example:
www.helpme.com?newpic.jpg
I am then trying to put the query string in
<IMG SRC="querystring" WIDTH=400 BORDER=0>.
I don't know how to get the query string to echo "newpic.jpg" in the htm
command in the pop up window.

Thank You.

Paul
 
D

DU

P.L. Owens said:
I am trying to open a pop-up window with its own htm code, in order to show
an enlargement of a thumbnail. But I am passing a query string after the? in
the url of the new window. for example:
www.helpme.com?newpic.jpg
I am then trying to put the query string in
<IMG SRC="querystring" WIDTH=400 BORDER=0>.
I don't know how to get the query string to echo "newpic.jpg" in the htm
command in the pop up window.

Thank You.

Paul

Did you post this question a couple hours ago in other newsgroups? Just
asking...
 
P

P.L. Owens

Yes, on comp.lang.javascript but the answer did not quite work. Appreciated
it, but still trying to get some type of solution to the problem.

Paul
 
T

Toby A Inkster

P.L. Owens said:
I am then trying to put the query string in
<IMG SRC="querystring" WIDTH=400 BORDER=0>.

If your server supports PHP, you could use something like:

<IMG SRC="<?= getenv('QUERY_STRING') ?>" WIDTH=400 BORDER=0>
 
A

Andy Dingley

I am trying to open a pop-up window with its own htm code, in order to show
an enlargement of a thumbnail. But I am passing a query string after the? in
the url of the new window.

HTML isn't executable code, so you can't do this in pure HTML alone.
You need some scripting somewhere, either on the server (probably
easiest), in the new window (JavaScript) or in the parent window with
the thumbnails (more JavaScript) .

Server-side code is easiest. Make a link URL like
www.helpme.com/image.php?image=newpic.jpg
image.php is a new script you write to load up the image you want.
Quite how you do this depends on what your server supports - it could
be PHP, but equally well Perl, ASP etc.


If you put the code client-side into the image viewing window, then
you need to extract the parameter from the URL, slice it up to an
image identifer, turn it into a relative URL, then write it into the
..src property of the <img> element.

BEGIN - Client-side image - viewer code
-------------------------------------------------------
<html><head>
<title>Image viewer</title>

<script language="JavaScript" type="text/javascript" >
<!-- //

window.onload = function () {

// Deal with the parameters
var strURL = document.URL;
var strQueryString = strURL.match (/\?(.+)$/);
if (strQueryString != null) {
var aryQueryStrings = strQueryString [1].split (/\&/);
var aryQueryParams = new Array();
for (var i=0; i < aryQueryStrings.length; i++) {
var strQueryParams = aryQueryStrings .split
(/=/);
if (strQueryParams) {
aryQueryParams [strQueryParams [0]] =
strQueryParams [1];
}
}
}

// Find the properties
var strImageID = aryQueryParams ['image'];
// Force a file extension
if (!strImageID.match (/\.jpg$/i)) { strImageID += '.jpg'; }
var strBaseURL = "\/ebay\/201203\/"; // Could load this
from params too

// Might test here and exit if there's no image to load


var strSrcURL = strBaseURL + strImageID;
// Could read these from the image, take it from a parameter
or anything
var strTitle = "Image " + strImageID;
var strLongDesc = "URL " + strURL + "\nImage " + strImageID;

// Find the targets and display the properties
document.title = strTitle;
var elmImg = document.all.imgZoom;
if (elmImg) {
elmImg.src = strSrcURL;
elmImg.alt = strTitle;
elmImg.longdesc = strLongDesc;
}
var divCaption = document.all.divCaption;
if (divCaption) {
divCaption.innerText = strLongDesc;
}
}

// -->
</script>


</head><body >

<img id="imgZoom" src="" alt="" />
<p id="divCaption" class="caption" ></p>

</body></html>

-----------------------------------------------------
END - Client-side image - viewer code




Placing the code into the parent window can use either
window.open(URL) to open a window as we've already described, or it
might use window.open() and then use document.write() to generate the
HTML within it. I like this method myself, as it avoids another round
trip to the server.

var wndViewer = window.open("", "_imagegallery",
"height=500,width=500,menubar=no,resizable=yes")

var docImageView =wndViewer .document;
docImageView.write("<html><head>")
docImageView.write("<title>" + title + "</title>")
docImageView.write("</head><body>")
docImageView.write("<img src='" + src + "' />");
docImageView.write("</body></html>")

wndViewer.focus();
return true; // Success




When you call the "view large image" code from the thumbnail gallery,
I suggest using code like this:

<a href="photos/im000501.jpg" target="_imageview"
onclick="return gallery_onclick('photos/im000501.jpg', 'Ashwell
Barn',
'Reconstructing an existing modern garage in a more sympathetic
timber framed vernacular, preserving the original roof cladding to
reduce costs.');"
<img src="photos/im000501_thumbnail.jpg" alt="Ashwell Barn" /></a>

gallery_onclick() returns true if successful, which terminates
navigation at that point. However if JavaScript isn't available to
that client, then the normal <a href="" > navigation takes its place
and you get a non-JavaScript window opened .
 

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
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top