By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,167 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,167 IT Pros & Developers. It's quick & easy.

problem using javascript to get querystring

P: n/a
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");
//
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
See the escape() and unescape() function. Use it to correctly encode
your query strings.

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

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.