SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    application/xhtml+xml Content-Type and JavaScript

    Hi all,
    I serve my site as application/xhtml+xml Content-Type for compliant browsers via a PHP script.
    I need a bit of JavaScript into the markup (a script tag calling a external file) in order to show up the Google ad Sense .
    All works fine in IE (receive my code as text/html) but the ads vanishes in FireFox.
    Are there a way to fix this without change my DOCTYPE or the Content-Type?
    Mauricio Samy Silva
    http://www.maujor.com/

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd just give the firefox users a break from the ads.

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Google probably uses document.write() which is not compatible with X(HT)ML parsers.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    code?

    Can we see the Javascript you are using? I find it hard to believe that Google ads aren't working in a browser...

    Dave

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    I just double checked the code and Google definitely uses document.write to write out the ads and that is incompatible with XHTML. If you want anything written via document.write to appear in your web page the page MUST be served as HTML and the document.write statements run before the page finishes loading.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,
    Thank you for take your time.
    I was affraid that there isn't a fix and now I know that I must make a choice:
    Don't serve de Google ads to my compliant browsers users or change the Content-Type for serve my webpages.
    Unfortunate actually I think that the "universal web" is an utopia.

    Edit: Hi Dave
    The Googles code is here: http://pagead2.googlesyndication.com/pagead/show_ads.js
    but as Stephen pointed out Google uses document.write that is incompatible with my Content-Type
    Last edited by Maujor; Dec 13, 2006 at 16:37. Reason: Answer to dwees
    Mauricio Samy Silva
    http://www.maujor.com/

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Possible solution

    Hey there,

    If you use an Iframe, can't you mix document types on the same page?

    Create an Iframe that only appears in compliant browsers, and have the src of that iframe be a dummy HTML document type file with the Google Ad js inside it.

    It will end up showing an Iframe inside an Iframe, but the Google JS probably won't care. You'll just have to make sure to remove the border/scrolling from your Iframe.

    Dave

  8. #8
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dave,
    I'd like to go further into your solution but, I can't figure out how to make the Google JavaScript code run by simple calling the nake code into an iframe. I think that de code must be enclosed by SCRIPT tags and that it's forbidden to host a modified version of the Google code in my host for this pourpose.
    Or am I missing something? Excuse me!

    If you use an Iframe, can't you mix document types on the same page?
    Yes we do!
    But iframe isn't allowed in Strict documents. (I use XHTML 1.1)
    You must use XHTML Transitional.
    Mauricio Samy Silva
    http://www.maujor.com/

  9. #9
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz View Post
    Google probably uses document.write() which is not compatible with X(HT)ML parsers.
    And how about to skip the parse using CDATA. Is it possible?
    I give a try but it seems that the differents sintaxes for CDATA is wrong or misunderstood here :-(.
    Mauricio Samy Silva
    http://www.maujor.com/

  10. #10
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CDATA wouldn't help because the script element that contained the document.write() calls would be ignored if it was in a CDATA section.

    This is one of the many reasons why I recommend HTML 4.01 Strict over everything else.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  11. #11
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replacing Iframe with Object tag

    You can use an Object tag like:

    Code:
    <object data="google.html" type="text/html"></object>
    in XHTML 1.1. However this isn't properly supported by all browsers, so you would have to use some browser sniffing to replace the object tag with an iframe in certain browsers.

    I've been working on this, and I can get the google ads js to be loaded, but it throws an error as is (b has no properties on line 9). Is this the same error you were seeing?

    Dave

  12. #12
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simply use HTML 4 as Kravvitz proposed instead. I don't see the benefits of using XHTML today. Using an iframe will also brake your XHTML validation (if you would care about that).

  13. #13
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks guys.
    For now I've changed my webpages to XHTML 1.0 Strict and I'm serving them as text/html.
    This is the easiest solution for my site.

    PS: If it's relevant the site is hosted at: http://www.maujor.com/
    Administrators: If you consider the link auto promotion, please delete it.
    Mauricio Samy Silva
    http://www.maujor.com/

  14. #14
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The article "XHTML is dead" might be interesting for you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •