View Full Version : How to transfer one file/variable/item from one page to another?
jianneng
10-07-2002, 01:25 PM
Hi,
I am not sure if JavaScript can do this, but this is the problem. I have many pictures in BMP format which I put them on a source page (much like a gallery). Let say I got Picture A, Picture B, and Picture C, so whichever I click on one of them, this picture will appear on the second page, or the destination page. That means, if I click A, A will appear on the second page. I want my destination page to be a dynamic page which can show any of the pictures on the source page so that I don't have to create a similar page for each of the pictures, which is tedious.
Can someone show me any guides or source code which I can solve this problem? Thanks.
jianneng
10-08-2002, 10:08 AM
Hi Moderator, thanks for your code...I am still trying to understand the two javascript. Can you spend some time to clarify my doubts here?
1. The variable mystring...so using GET method in the source page, this variable mystring refers to all my pictures, right? If the filename of the picture is APPLE.BMP, so mystring will refer to this picture?
2. Do I need to put any of these two javascripts on my destination page? Or I just create a blank HTML page (or no need at all)?
Thanks!
glenngv
10-08-2002, 10:29 AM
try this:
<html>
<head>
<title>My Gallery</title>
<script language="javascript">
<!--
function openImage(img){
win = window.open("","","scrollbars=1,resizable=1,width=800,height=600");
win.document.write(
"<html><head><title>" + img + "</title></head>" +
"<body><center><img src=\"" + img + "\"">" +
"<br><input type=button value='Close' onclick='window.close()'></center>" +
"</body></html>"
);
win.document.close();
win.focus();
}
//-->
</script>
</head>
<body>
<a href="javascript:openImage('image1.gif')"><img src="image1.gif" border="0"></a><br>
<a href="javascript:openImage('image2.gif')"><img src="image2.gif" border="0"></a><br>
<a href="javascript:openImage('image3.gif')"><img src="image3.gif" border="0"></a><br>
<a href="javascript:openImage('image4.gif')"><img src="image4.gif" border="0"></a>
</body>
</html>
whammy
10-08-2002, 04:00 PM
Answers:
1. Yes
2. Yes (to the former, of course you have to have the scripts on your page in order for them to work!)
And to further clarify how you can use this approach:
<script type="text/javascript">
<!--
function QueryString(str){
var q = window.location.search;
var foundValue = ""
if(q.length > 1){
this.q = q.substring(1, q.length);
}
this.keyValuePairs = new Array();
if(q){
for(var i = 0; i < this.q.split("&").length; i++){
this.keyValuePairs[i] = this.q.split("&")[i];
if(this.keyValuePairs[i].split("=")[0] == str){
foundValue = unescape(this.keyValuePairs[i].split("=")[1]);
}
}
}
return foundValue;
}
//-->
</script>
<script type="text/javascript">
<!--
document.write("<img src=\"" + QueryString('pic') + "\" width=\"" + QueryString('width') + "\" height=\"" + QueryString('height') + "\" />");
//-->
</script>
Click the link below to see it working:
http://www.solidscripts.com/querystring.htm?pic=mypicture.jpg&width=214&height=118
Of course, you would just use a different picture name in the querystring to change the picture displayed...
:)
adios
10-08-2002, 06:30 PM
This is really primitive, but take a look:
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
var lefty = righty = null;
function pop_twins() {
lefty = open('lefty.htm','lefty','left=0,top=0,width='+screen.availWidth/2+',height='+screen.availHeight+',status=0');
righty = open('righty.htm','righty','left='+screen.availWidth/2+',top=0,width='+screen.availWidth/2+',height='+screen.availHeight+',status=0');
lefty.focus(); righty.focus();
}
</script>
</head>
<body>
<a href="javascript:void pop_twins()">pop 'em</a>
</body>
</html>
[lefty.htm]
<html>
<head>
<title>The Source</title>
<base href="http://aabode.com/victoria/images/">
<script type="text/javascript" language="javascript">
var path = 'http://aabode.com/victoria/images/';
function addIMG() {
var HTML = '', img, box_arr = document.addform.ImgAdd, which = 0;
HTML += '<html><head><title>The Destination</title></head><body>';
HTML += '<h1>&#149; The Destination &#149;</h1>';
while (box = box_arr[which++]) if (box.checked)
HTML += '<img vspace="5" border="1" src="' + path + box.value + '"><br>';
HTML += '</body></html>';
if (opener.righty) {
opener.righty.document.write(HTML);
opener.righty.document.close();
}
}
</script>
</head>
<body>
<h1>&#149; The Source &#149;</h1>
<form name="addform">
<input type="checkbox" name="ImgAdd" value="apple.jpg" onclick="addIMG()">
<img align="middle" vspace="5" border="1" src="apple.jpg"><br>
<input type="checkbox" name="ImgAdd" value="strawberry.jpg" onclick="addIMG()">
<img align="middle" vspace="5" border="1" src="strawberry.jpg"><br>
<input type="checkbox" name="ImgAdd" value="pumpkin.jpg" onclick="addIMG()">
<img align="middle" vspace="5" border="1" src="pumpkin.jpg"><br>
<input type="checkbox" name="ImgAdd" value="lettuce.jpg" onclick="addIMG()">
<img align="middle" vspace="5" border="1" src="lettuce.jpg"><br>
<input type="checkbox" name="ImgAdd" value="raspberries.jpg" onclick="addIMG()">
<img align="middle" vspace="5" border="1" src="raspberries.jpg"><br>
<input type="checkbox" name="ImgAdd" value="tomatoes.jpg" onclick="addIMG()">
<img align="middle" vspace="5" border="1" src="tomatoes.jpg">
</form>
</body>
</html>
[righty.htm]
<html>
<head>
<title>The Destination</title>
<body>
<h1>&#149; The Destination &#149;</h1>
</body>
</html>
Close? Not so close? Wrong planet...?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.