aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes & in URL query String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "& in URL query String" Watch "& in URL query String" New topic
Author

& in URL query String

Kevin manoj
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
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

Joined: Dec 11, 2004
Posts: 13410

& 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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Using & in JavaScript does not have to be escaped like in html markup.

Eric
Kevin manoj
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
Thanks for quick reply. The answer is very helpful.


Thanks sincerely again
Eugenio Pacheco
Greenhorn

Joined: Mar 18, 2008
Posts: 5
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

Joined: Dec 11, 2004
Posts: 13410

That looks like a valid query string.
What problem are you having?
Eugenio Pacheco
Greenhorn

Joined: Mar 18, 2008
Posts: 5
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

Joined: Mar 18, 2008
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61628
    
  67

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eugenio Pacheco
Greenhorn

Joined: Mar 18, 2008
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61628
    
  67

WHat are you doing with the url string after it is created?
Eugenio Pacheco
Greenhorn

Joined: Mar 18, 2008
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61628
    
  67

How is it getting there? Something is encoding the value prior to use.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.
 
Consider Paul's rocket mass heater.
 
subject: & in URL query String