• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

& in URL query String

 
Kevin manoj
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a javascript function like following:
---
function gotoProvince(region)
{

location.href = 'http://www.XXX.XXX/shopping/productdetail.jsp?regionToggle=true&languageToggle=true&content=/portlets/personal/wireless/product_details.jsp&metaKey=PrsShpWls_Content&wlcs_catalog_item_sku=66282&INT=MOB_SA_Q4_BBPearl_LM_wlpbest®ion=' + region + '&language=en';

}
---
A JSP file writes out the html code and javascript function. This function is to switch the province selection.

The wierd thing is that it works fine in IE6, but it did not work in Firefox. In firefox, it seem that it treat & as ampersand and amp; as a part of query parameter.

Fox example, the above link:
'amp;language' becomes the parameter key, and en becomes the parameter value

Why firefox and IE6 interpret the query string in a different way?

Thanks in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
& is not the proper URL escape sequence for an ampersand.
%26 is.

& is the HTML escape sequence.
[ January 22, 2008: Message edited by: Ben Souther ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using & in JavaScript does not have to be escaped like in html markup.

Eric
 
Kevin manoj
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for quick reply. The answer is very helpful.


Thanks sincerely again
 
Eugenio Pacheco
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having a similar problem. I'm trying to send a querystring such as:

document.sendin.dst.value = "http://myserver.com/balance.php?un=" + document.login.username.value + "&link=1";

On IE it works perfectly, on FireFox it shows the following at the address bar:

http://myserver.com/balance.php?un=username&link=1

I read what was said in this post and I tried changing from & to & and to %26, neither one worked.

Thanks in advance for any help given.

Eugenio Pacheco
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like a valid query string.
What problem are you having?
 
Eugenio Pacheco
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm sorry, I made a mistake, on FireFox it shows:

http://myserver.com/balance.php?un=username&link=1

That's the problem.

Regards,

Eugenio Pacheco
 
Eugenio Pacheco
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It's weird... In the post I'm not being able to show "& amp ;"... That's what shows instead of & directly... It shows the "& amp ;" before link on the address:

http://myserver.com/balance.php?un=username"& amp ;"link=1 (no spaces and no quotes)

Regards,

Eugenio Pacheco
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugenio Pacheco:
It's weird... In the post I'm not being able to show "& amp ;"... That's what shows instead of & directly...

Of course any HTML entity you type in is going to get interpreted by the browser for display.

It looks like something is HTML-encoding your query string. How is the query string being generated?
 
Eugenio Pacheco
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

To generate the string it takes the value of a hidden field inside a form:

document.sendin.dst.value = "http://myserver.com/balance.php?un=" + document.login.username.value + "&link=1";

That produces the result fine on IE6, but it shows & amp ; instead of just &.

Regards,

Eugenio Pacheco
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WHat are you doing with the url string after it is created?
 
Eugenio Pacheco
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I use that value in a meta tag for refresh.

The really weird thing is that on IE6 it works perfectly on FireFox it doesn't.

Thanks for the help.

Eugenio Pacheco
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is it getting there? Something is encoding the value prior to use.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugenio Pacheco:
Hi,

I use that value in a meta tag for refresh.

The really weird thing is that on IE6 it works perfectly on FireFox it doesn't.

Thanks for the help.

Eugenio Pacheco


That's not really weird.
Browser incompatibility is a common issue in web development.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic