Welcome to WebmasterWorld Guest from 54.162.93.137

Forum Moderators: open

Message Too Old, No Replies

when pasting javascript into page & in string mangles code

     
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){
document.location=url;
}

foo('/test.html?boo=1&copy=2');


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:

foo('/test.html?boo=1@=2');


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

foo('/test.html?boo=1&copy=2');


That effectively means this is being done

document.location='/test.html?boo=1&copy=2';


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?
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