Hi guys,

I'm very new to Javascript and normally I can find solutions for any issues I have with a quick Google search but this one I just can't find a solution that works.

Essentially all I'm trying to do is insert a bit of adsense code into a part of my site.

The site displays totally fine in Firefox, Chrome and Safari but Internet Explorer is causing me a world of problems.

As you can see in the images below IE won't render the page fully and throws up what looks like an iframe with a 400 error in it...

This is the Firefox version, how I want it to look...
[IMG][/IMG]

This is the IE version, with the errors...
[IMG][/IMG]

The code I am using is this:

<!--begin header--!>
<table id="header">
<tr>
<td id="header-logo"></td>
<td id="header-ad">
<script type="text/javascript">
<!--
google_ad_client = "pub-5706391847687826";
/* 468x60, created 20/07/09 */
google_ad_slot = "0680301869";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
</tr>
</table>
<br><br>
<!--end header--!>

So far I have tried conditional commenting which doesn't work. I have also tried using a simple Javascript code which shows different text for different browsers, this didn't work either.

Also, if I replace the Adsense code with just a simple bit of text, the page renders the same in both browsers (as the Firefox example above).

Any help is very very much appreciated...

Thanks,

Dani AI

Generated

Good catch by — this was caused by malformed HTML comments (the stray ! at the end of the comment markers). Browsers differ in how they recover from parse errors; Firefox and Chrome were forgiving and continued parsing the AdSense script, but IE’s parser handled the broken comment differently, which corrupted the DOM/script parsing and produced the iframe/400 behavior you saw.

Why that breaks ads: the AdSense snippet runs a script that injects an iframe. If the script tag is accidentally left inside an unclosed or malformed comment (or if surrounding tags are unclosed), the ad script can be truncated or malformed and the network request to the ad server can fail. Fixing the comment usually cures it, but similar stray characters or unclosed tags will cause the same symptoms.

Quick checklist to prevent and debug this kind of problem:

  • Validate the page markup (look for unclosed comments/tags).
  • Use IE’s Developer Tools (F12): check the DOM/HTML output, the Console for JS errors, and the Network tab for the 400 on the ad request.
  • View source to spot stray characters (extra !, mismatched <!-- -->, etc.).
  • Ensure a standards DOCTYPE (e.g. <!DOCTYPE html>) so you’re not in quirks mode.
  • Don’t hand-edit vendor snippets — paste them exactly as provided and load them over the correct protocol.

Final note: avoid wrapping script blocks in nonstandard comment hacks. Once the comments/tags are corrected the layout and AdSense iframe should load consistently in IE and other browsers. Thanks to for spotting the typo, and glad that it turned out to be a quick fix.

Recommended Answers

All 2 Replies

Html comments are <!-- --> and not <!-- --!>.
Try replacing

<!--begin header--!>

with

<!--begin header-->

and so on in the rest of the html code

I really don't know whether to laugh or cry after spending hours looking for a fix and it turns out to be the comments!

Thanks a million!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.