Click to See Complete Forum and Search --> : Passing strings


krugos
09-16-2003, 09:36 AM
Hi, I need to pass a string from one page to another when a link is clicked. When the link is clicked I need a new page to load and for some javascript in the new page to use a string, passed from the old page (this will be the name of an image) to load the image. This will save me from having a page for each large image in my system. Any ideas to do this? I had thought of redirecting to blah.html?imname=bob and then picking up that attribute in the next page. I know this is doable in JSP but I need to do it in either Javascript or HTML.

Regards,
Matt.

Khalid Ali
09-16-2003, 10:02 AM
There are fw options for you to use.

suppose image name

var img = "images/flakes.gif";

and the url to the next page is

var url = "pages/nextpage.html";

1. apend the image name to the url of the next page and direct to the next page

window.location.href = url+"?imageName="+img;

2.if the next page is a child window opened from the parent using
window.open

then you can use access these values irectly from child

top.opener.url

3. is to use cookies, set cookie at first page and then read cookie at the next page

krugos
09-16-2003, 10:15 AM
Suppose I take option 1 of those, how do I then get the image name once I'm on the new page?
Matt.

Khalid Ali
09-16-2003, 10:26 AM
Suppose there is only one image name that you are passing to the next page.

var searchStr = window.location.search;

the above willreturn everything after the ? mark in the URL
and since we know that search string format is

imageName = images/flakes.gif

now we need to remove the variable name and the = (comparison sign)

var imgName = searchStr.substring(searchStr.indexOf("=")+1,searchStr.length);

lol..I have not tested it so am hoping it will give you the correct results..

Charles
09-16-2003, 11:08 AM
There's something about the title of this thread that makes me think of my youth, the cat having ingested tinsel from the Christmas tree. With Summer at its end and a hurricane on the way it's nice to be reminded of holidays to come.