Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

when pasting javascript into page & in string mangles code


abersoch windsurfer

11:40 pm on Feb 7, 2011 (gmt 0)

5+ Year Member

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!


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

2:07 pm on Feb 8, 2011 (gmt 0)

5+ Year Member

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month