Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Firefox is requesting a bogus URL from an IMG src in JavaScript code?

I'm getting weird 404 errors on my site for the following URL:

GET /%27%20+%20item.icon%20+%20%27 HTTP/1.1

I've got some corresponding code in my HTML file:

<script type="text/javascript">
  function foo(item) {
     return '<img src="' + item.icon + '">' : '';
  }
</script>

Seems to be coming from FireFox 3.5/3.6 on Windows only, but I can't guarantee that.

So, why would FF be requesting this URL? Is it trying to pre-load images or something? Any suggestions on how to stop it?

like image 396
Tom Avatar asked Jan 23 '23 13:01

Tom


1 Answers

Firefox is interpreting your code as XHTML. Try to put your code in a CDATA section like this:

<script type="text/javascript">
//<![CDATA[
  function foo(item) {
   return '<img src="' + item.icon + '">' : '';
  }
//]]>
</script>

See this page for a little more information about this problem.

like image 99
Benjamin Wohlwend Avatar answered Jan 25 '23 03:01

Benjamin Wohlwend