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

I get 404 weird errors on my website at the following URL:

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

I have the corresponding code in the HTML file:

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

It seems that from FireFox 3.5 / 3.6 only on Windows, but I can not guarantee this.

So, why does FF request this URL? Is he trying to preload images or something else? Any suggestions on how to stop it?

+4
source share
3 answers

Firefox interprets your code as XHTML. Try putting your code in the CDATA section as follows:

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

For more information about this issue, see this page .

+6
source

I have such an exact problem.

I can confirm that this is happening with Mac FF 3.6. It is only 3.6 pieces. It seems that even 3.7 alpha works, according to some people in the IRC, I tried this.

I can also confirm that the CDATA trick is not working; I have tried many options. I also tried different DOCTYPES etc.

I also have a terrible time reproducing it. This happens in about 30% of cases when I load a page, even if I follow the same steps every time w / r / t clears the cache, reloading FF, etc. It is definitely heisenbug. I cannot create a simple test case that works too. The trigger conditions for this should be quite complex.

However, I was fortunate enough to fix this. It seems that the key should kill src= . For example:

 var someHTML = '<img src="' + item.url + '" />'; 

becomes:

 var someHTML = '<img s'+'rc="' + item.url + '" />'; 

So far this seems to help, but for me it hasn't been long enough.

This problem is especially insidious in my case; I have a JSON string that has 20 URLs, and FF 3.6 requests all 20 URLs (which are dummy URLs but end up on the same page) in a split second and DoS server every time someone with FF 3.6 visits my site.

This is a very bad mistake in FF. I think that many webmasters have not yet discovered that this is happening, but I would suggest that this causes widespread problems.

+2
source

Well, it turns out that using the CDATA partition did not help in the end. Fixed by moving the function to a separate .js script file.

+1
source

Source: https://habr.com/ru/post/1301551/


All Articles