Forum Moderators: martinibuster
Is it impossible to put Adsense ads on the site without serving everything as text/html?
Dave
<snip>
Do you think this is ok with the Adsense TOS?
[edited by: Woz at 2:09 am (utc) on May 8, 2006]
[edit reason] no specifics please, see TOS#13 [/edit]
my site uses application/xhtml+xml too, and i don't even bother to check whether users have a decent browser. i just serve all the pages as that.
my google ads all display okay.
If you are really using just
application/xhtml+xml, then your page would not show AdSense, it would not open in Internet Explorer and would not be indexed by Googlebot or any other search engine. So if your ads are working and the site displays in IE, you are not using application/xhtml+xml (just setting this in a meta tag won't work). As for the method of using an
object tag to include a separate text/html document with the AdSense code in it, I do know that Google has in the past permitted it, but you really should seek explicit permission from Google before implementing it yourself - don't take my word for it. A couple of major issues remain, however, even if Google accept the use of this method. The first is that having the AdSense code in a separate file may well disassociate your ads from your content - the mediabot could consider only the include file as the display page, and as that file is empty your targetting will be all over the place.
The second major issue is your choice of using
application/xhtml+xml in the first place. Unless you have a specific need for it (mixing XHTML with other XML variants, for example) then choosing application/xhtml+xml (with MIME type switching) over text/html actively penalizes standards-compliant browsers which will not display a page with the slightest error, you slow down page rendering and add an unnecessary layer of complexity. You can read a recent HTML and Browsers thread Why most of us should NOT use XHTML [webmasterworld.com] for more information. Use XHTML syntax if you prefer it, but stick to
text/html if you are running AdSense or are trying to make money out of your site.
Currently I query the HTTP_ACCEPT header to determine what DOCTYPE and MIME type to use, and so to quickly change pages to HTML4 with a text/html I can fix the doctype, and use a php function to fix the tags ending like this " />".
Here's what I have in my 'doctype.php' php include:
<?php
$charset = "utf-8";
$mime = "text/html";
function fix_code($buffer) {
return (str_replace(" />", ">", $buffer));
}
ob_start("fix_code");
$prolog_type = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html lang='en'>";
header("Content-Type: $mime;charset=$charset");
print $prolog_type;
?> Hope this is useful to somebody.
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
the ads definitely display in firefox.
someone told me once that if you are using XHTML (and i use XHTML Strict which validates) then it is technically more correct to use that doctype over any other.
so were they just being pedantic?
So even if you could get the code to generate output, it would invalidate the XHTML document.
There is a page online that gives a suggestion for getting around this (by using an object element that specifies type="text/html" instead for browsers that know the main page is type="application/xhtml+xml") but I'm not sure if this would work.
Note that a meta tag mime-type declaration will be over-ridden by whatever is specified (if anything) in the HTTP header. I bet that's why your ads show in Firefox - the pages are probably being served as text/html.
You can set the mime type in the header in a php-generated page with lines like this:
$charset = "utf-8";
$mime = "text/html";
header("Content-Type: $mime;charset=$charset");
UserFriendly - you're right about that. The method which I found which uses the object tag to import the Adsense code actually imports a complete html page - html 4.01 loose doctype and everything - which contains the Adsense code. The imported page has a meta tag which specifies the mime as text/html, which works. Firefox displays the page and the ads show up. I think the ad targeting might get messed up though, because the Adsense code isn't technically part of the parent page.
Dave