开发者

Heavy Javascript with URLs causes Chrome (DevTools?) to report bad 404's

开发者 https://www.devze.com 2023-04-12 12:46 出处:网络
A page containing a good load of javascript also contains URLs encoded within the javascript as JS strings.

A page containing a good load of javascript also contains URLs encoded within the javascript as JS strings.

The problem is that Chrome (or perhaps just it's Developer Tools?) is trying to navigate to these encoded URLs as if they were a part of the HTML.

This only seem开发者_运维百科s to happen when there is a lot of javascript in the page.

The page looks more or less like:

<body>
    ....
    <script type="text/javascript">
        //<![CDATA[
        google.maps.event.clearListeners(window.kgmm["marker32"],"click");
        google.maps.event.addListener(window.kgmm["marker32"],"click",clicked);
        window.kgmp["marker54"]=new InfoBox({
            content: "<div class=\"wrapBox\" align=\"left\"><div class=\"imageBox\"><a href=\"#ir_rih\" target=\"_blank\"><span class=\"imageWrap\">"

/* the issue -> */  +"<img src=\"?ajax=1&cls=owAjaxHandler&mtd=thumbnail&amp;i=wp-content\/uploads\/2011\/07\/Bahrija &amp; Fomm ir-rih08.jpg&amp;w=115&amp;h=115\" border=\"0\" alt=\"\"\/><\/"

                    +"span><\/a><\/div><div class=\"specsBox\"><h2>Fomm Ir-Rih<\/h2><div class=\"shortDesc\"><\/div><a class=\"moreInfo\" href=\"#ir_rih\" onclick=\"return krtShowTabByHash(this);\">more details &raquo;<\/a><\/div><\/div>" ,
            disableAutoPan: false,
            maxWidth: 0,
            pixelOffset: new google.maps.Size(-214, 0),
            zIndex: null
        });
        //]]>
    </script>
    ....
</body>

The following is a screenshot on how it looks like in the console:

Heavy Javascript with URLs causes Chrome (DevTools?) to report bad 404's


Be warned that I'm not looking for a fix. Please don't advise on any way to improve the code.

Rather than a fix, I'm looking for an answer as to why this is happening.

NB: Wasn't CDATA supposed to stop chrome from parsing the javascript contents as XML elements?


Sample URL causing the issue:

  1. First, go here.
  2. Open the console (Right Click -> Inspect Element -> Console tab)
  3. Click on the second item in the page list, named "Mdina, Rabat, Dingli & Baħrija"
  4. Keep looking at the console while the page loads, you should see the aforementioned errors.

NB: Someone has marked the question as "too localized". I'd like to point out that that is not true. I've encountered this issue on multiple websites,but never gave it much thought (until now) because the website still works.


I'd put dollars to donuts that the problem is your escaping of the i url parameter:

src=\"?ajax=1&cls=owAjaxHandler&mtd=thumbnail&amp;i=wp-content\/uploads\/2011\/07\/Bahrija &amp; Fomm ir-rih08.jpg&amp;w=115&amp;h=115\"

Basically, backslash escaping does not work for URLs. If you wanted to go to that URL, you'd need to send it as:

src=\"?ajax=1&cls=owAjaxHandler&mtd=thumbnail&amp;i=wp-content%2Fuploads%2F2011%2F07%2FBahrija%20%26%20Fomm%20ir-rih08.jpg&amp;w=115&amp;h=115\"

Chris Edit: Decoding it as a javascript string would yield:

src="?ajax=1&cls=owAjaxHandler&mtd=thumbnail&amp;i=wp-content/uploads/2011/07/Bahrija &amp; Fomm ir-rih08.jpg&amp;w=115&amp;h=115"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号