Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts

    document.write SEO question

    Can search engines read document.write()? I believe it can read the Php "echo", correct? Which one would be the best?

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    ASP and PHP both happen on the server side before the page is delivered to the user agent. SE's don't know or care how you create the HTML that they end up reading.

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    yes...but as javascript is client-side, SEs wont read it would they?

  • #4
    New Coder
    Join Date
    Sep 2007
    Location
    Hanoi, Vietnam
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes just because Javascript is client side, so what you (visitor) read on the browse is the content that document.write() write out. But SEs and another spiders will get only document.write() statement.

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Alright! Thanks nothinglastz and pennimus!

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Anything that can be done with document.write can also be done server side. If you have a server side language available to you then use that and forget the antiquated unnecessary JavaScript document.write statement.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    I wouldn't call it antiquated and unnecessary....but i definately see your point, and I will use the PHP echo instead of document.write.

  • #8
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    This is very interesting...I should have checked this in the very first place, but I didn't think of it. I googled my site and checked google's cache of it, and surprisingly it displayed my menu in the cache, although I have my menu written all the way from a completely external javascript. Does this mean google can read document.write?

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by binaryWeapon View Post
    I wouldn't call it antiquated and unnecessary....but i definately see your point, and I will use the PHP echo instead of document.write.
    The limitations on where you can use document.write mean that it can only be used where a server side script could have generated the content instead and done so even where JavaScript is disabled. Since using a server side script is always the better choice than using document.write it is therefore only necessary where the web page doesn't have access to use server side scripting and since all paid hosting has server side scripting that means that it would only ever be necessary for some free hosting.

    Where you do want JavaScript to write to your page then the best way to do it is to use the Document Object Model commands that are there specifically for that purpose. They will always work provided that JavaScript is enabled.

    If you don't want to use the DOM and do it according to the standards then you can use innerHTML which is supported by all modern browsers and will also work as long as JavaScript is enabled and the page uses HTML (not XHTML).

    document.write doesn't only not work when JavaScript is not enbled, it also doesn't work once the web page finishes loading and it doesn't work if the page uses XHTML instead of HTML.

    Anywhere that you can use document.write you could use server side processing. If server side processing is not available then anywhere you can use document.write you can use innerHTML or the DOM instead and achieve better separation between your HTML and JavaScript.

    document.write is therefore completely unnecessary and antiquated as it does not support the latest standards in how you should write your HTML and JavaScript.

    The only real use that document.write has had over the last five or so years since its use in proper JavaScripts became obsolete is as a simple way of outputing the result of running JavaScript code for people learning how to write JavaScript. Once they are half way through learning how to code JavaScript and learn about innerHTML and the DOM then they can and should completely forget about document.write.

    Using document.write in a script is an indication that either the person who wrote the script does not really know how to write JavaScript OR the script was written several years ago and really ought to be rewritten to modern standards.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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