Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer: HTML entities in URL

I have got the following PHP code:

echo "<input type='image' src='myImage.png' onClick='javascript:location.href = \"index.php?p=1&copy=true\"' />";

If I click on the image, Chrome redirects to index.php?p=1&copy=true. But if I click on the image in Internet Explorer 11, it redirects to index.php?p=1©=true.

Internet Explorer seems to replace HTML entities in URLs.

I tried using &amp; instead of &, but I got the same problem: IE replaces it into the copyright symbol.

How can I use &copy in my URL? I know that one possible solution would be to replace &copy with &whatever, but than I must change my hole system.

There are also other people with the same problem:

https://gist.github.com/pguillory/5136408

like image 788
mhellmeier Avatar asked Mar 10 '23 14:03

mhellmeier


2 Answers

The correct version is with the &amp;. Sadly, though, IE11 does indeed have a Big Old Bug in it causing it to take &amp;copy and turn it into the copyright symbol.

I found a workaround: Percent-encode the c in copy:

echo "<input type='image' src='myImage.png' onClick='location.href = \"index.php?p=1&amp;%63opy=true\"' />";
// --------------------------------------------------------------------------------------^^^

Example of the correct version that nevertheless fails on IE11: http://jsbin.com/dajihiwiwo/

Example of the above (which is also correct, just more obtuse) which works on IE11: http://jsbin.com/nehuxazeka/

like image 156
T.J. Crowder Avatar answered Mar 16 '23 12:03

T.J. Crowder


Why not just swap the variables?

Instead of index.php?p=1&copy=true it should still work with index.php?copy=true&amp;p=1.

like image 38
LooInSpain Avatar answered Mar 16 '23 13:03

LooInSpain