Connecting Tech Pros Worldwide Help | Site Map

problem using javascript to get querystring

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 10:22 AM
lion
Guest
 
Posts: n/a
Default problem using javascript to get querystring

my Problem:
a query string passed into a html page doesn't display correctly on a
mac
I am just using html and javascript (no ASP, PHP or server side
scripting)

This is the query string:
popup.html?pImage=30_leilani_dowding_b_060.jpg&ord Ref=1000&Title=Leilani Dowding

using the QueryString function below, the pImage variable should be
equal to: 30_leilani_dowding_b_060.jpg
on a PC this is correct BUT on a mac it is displayed as:
'30_leilani_dowding_b_06030_leil'?

Has anyone experienced this problem?

cheers, lion

javascript to to display the image
<SCRIPT LANGUAGE="JavaScript">
document.write("<img src=images/wallpapers/"+pImage+" width='128'
height='128'>");
</script>

javascript function to get query string:
function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");

for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}

}

QueryString_Parse();

//set up the variables
//ordRef gets the order Number used i.e: 1000
var ordRef = QueryString("ordRef");
//
//Title gets the title passed e.g: Jordan&nbsp;Coldanski
var Title = QueryString("Title");
//
//pImage gets the image name including extension pImage=Jordan128.gif
var pImage = QueryString("pImage");
//

  #2  
Old July 23rd, 2005, 10:22 AM
Vincent van Beveren
Guest
 
Posts: n/a
Default Re: problem using javascript to get querystring

See the escape() and unescape() function. Use it to correctly encode
your query strings.

For example 'test.html?foo='+escape('big bar')

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.