homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

when pasting javascript into page & in string mangles code
abersoch windsurfer

5+ Year Member

Msg#: 4263993 posted 11:40 pm on Feb 7, 2011 (gmt 0)

I have some javascript that people paste into web pages. It makes use of a function that accepts a url string as an argument e.g.

function foo(url){


However for 'some' people pasting the code into their web page the & in the string is being treated as an entity resulting in the pasted in function call becoming:


I thought that it was safe to use & inside javascript blocks? Maybe its their editors or something?

In any case it happens sometimes and I need to fix it. Is it safe to use & in the function call code paste instead of & i.e


That effectively means this is being done


and didn't think you should do that in the javascript code

I am getting more confused the more a think about it!



Msg#: 4263993 posted 8:33 am on Feb 8, 2011 (gmt 0)

i'm not really understand about what you mean, but do you have try encodeURI() function?

abersoch windsurfer

5+ Year Member

Msg#: 4263993 posted 2:07 pm on Feb 8, 2011 (gmt 0)

Its alright I think Ive found the problem. I give the javascript code to embed on a web page and it is on that page that I do not encode the url string so some people see and hence grab mangled widget code.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved