php - How do I prevent internet explorer from rewriting my text? -


i have javascript variable contains url, populated outputting script tag php. intention change webpage url under circumstances.

var url = "/somepage?q=3&region=1";

the problem url contains sequence "&reg" internet explorer changes "®" without being asked.

i've tried escaping whole url htmlspecialchars, breaks other browsers. turning off quirks mode might help, it's not option current system. adding script tag did nothing.

edit: figured out 1 solution, "escaping" url concatenation.

var url = '<?php implode( "&'+'", explode( '&', '/somepage?q=3&region=1' ) ); ?>';

i realized should mention how change page:

document.location.href = url;

edit: turns out had error in script tag. minimal example shows same "problem":

<script type="text/javascript" />     var url = "/test?mode=preview®ion=1"; </script> 

the self-closing start tag important thing here.

it should var url = "/somepage?q=3&amp;region=1";

always use &amp; in urls browser understands query separator , doesn't think refers htmlentity (the problem here ie doesn't care if semicolon present or not , assumes &reg should &reg;)

edit: real context added after answered , pointed out in question , in comments, shouldn't use &amp; if intend use variable redirect using window.location

but, since have php @ hand, suggest using php code if javascript redirect not part of other complex script:

<?php header('location: http://domain/somepage?q=3&region=1'); exit(); ?> 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -