开发者

Could Firefox be automatically pre-loading html elements?

I have a JavaScript variable that holds an image tag surrounded by an anchor tag. Pretty normal stuff.

myvar="<a href='foo'><img src='bar'></a>";

What happens in Firefox, is that even though I'm not choosing to document.write the contents of that myvar variable, I nevertheless see that the image referenced by the IMG tag does actually get loaded. You'd never know it's happening without having a HTTP proxy tool running. I see in Fiddler that image being loaded. I don't see the image in the page of course, because开发者_Python百科 I didn't choose to document.write the tag into the page.

Is Firefox trying to be too clever and not-so-intelligently parsing through the HTML page, even through the embedded JavaScript in the page, and seeing an IMG tag and pre-loading it? It's the only explanation I have.

I'd have tried breaking up the img tag if I could recreate it in a simple test page, but I can't. If anyone here tells me yes Firefox 4+ definitely does that, then I'll change it to something like

myvar="<"+"a href='foo'><i"+"mg src='bar'></"+"a>";.

It'll be sad to have to do that (or one of the many other alternatives) but it'll work.


Is the JavaScript loaded from an external .js file or inlined in a script tag ? If inlined, you should make sure that it is not parsed as HTML content, instead declaring it as CDATA:

<script type="text/javascript">//<![CDATA[

// JS Stuff

//]]></script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜