homepage Welcome to WebmasterWorld Guest from 54.161.166.171
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
document.write problems
AlexB77




msg:4402933
 1:10 pm on Jan 2, 2012 (gmt 0)

Hey Guys,

Happy new year to you all!

Here is my problem, I have the following script
<script type="text/javascript">
document.write('<div class="g-plusone" data-size="medium"><\/div>');
</script>


IMO the output of this script should only be the part that document.write prints in to the source code:
<div class="g-plusone" data-size="medium"></div>


but, here it goes, the problem is that when I open my source code after the page is loaded I still have the entire code like the one on top printed in it. Any Idea why, or what I might be doing wrong?
Or might be there are any server settings that are not activated and need to be? Please help.

 

penders




msg:4402949
 3:32 pm on Jan 2, 2012 (gmt 0)

Because when you view the source of the page you are doing exactly that - viewing the original source code of the page, not the generated page that you see before you in the browser after all the script has been processed.

Traditionally this is the same source that search engines see, which is why they generally do not pick up content that is generated by JavaScript. (Although G can execute some script these days.)

In Firefox you can view the 'generated' source by selecting a portion of the page and choosing 'view generated source' from the context menu. Or, if you have the webdeveloper toolbar installed, this has a similar option for viewing the entire page (but this actually just selects the entire page and views the generated source in the same way).

AlexB77




msg:4403059
 12:45 am on Jan 3, 2012 (gmt 0)

Thanks for your help, but I think that there is more to it.

The reason why I am saying so is: When I check page of my site and page from my competitor on W3C, the code shown as
<script type="text/javascript">
document.write('<div class="g-plusone" data-size="medium"><\/div>');
</script>
but when the page opens in IE, for instance and after viewing source code in IE the script remains as above in the source of my page when it some how extracts into
<div class="g-plusone" data-size="medium"></div>
in the source code of the competitors page. So I thought that the might be something wrong with my server settings or may be somthing else, I just do not know.

So if anyone has any Ideas, please share

Marshall




msg:4403081
 4:22 am on Jan 3, 2012 (gmt 0)

To my knowledge, you will always see the script in the source code and the output in the page view. Basically, what penders said.

Marshall

penders




msg:4403149
 12:28 pm on Jan 3, 2012 (gmt 0)

When I check page of my site and page from my competitor on W3C...


What do you mean? By Validating both pages in W3C's HTML validator and selecting the option to view source?

The source code you view in IE should be the same as the source seen by W3C. However, it is possible that your competitor is 'cloaking' and serving different content to IE and W3C?! If you can see...
<div class="g-plusone" data-size="medium"></div>

in the source of the page in your browser, when you simply "view source" then they have not used JavaScript to write this content, they have hardcoded it as HTML, which they might have done conditionally using a server-side detection script!?

rocknbil




msg:4403222
 5:13 pm on Jan 3, 2012 (gmt 0)

Perhaps your competitor is (correctly) doing some sort of progressive enhancement. That is, if Javascript cannot be executed, just output

<div class="g-plusone" data-size="medium"></div>

The Javascript should still be present, it's just that a non-Javascript clients won't do anything with it. As mentioned, a method of serving different content based on the client may be in place. There are a number of ways you would do that: .htaccess directives, server-side scripts, it depends.

(Though I can't see how doing that would be of any advantage, the plusone and related technologies are all Javascript driven . . . )

AlexB77




msg:4403354
 12:10 am on Jan 4, 2012 (gmt 0)

@penders

What do you mean? By Validating both pages in W3C's HTML validator and selecting the option to view source?
I am doing exactly this.

I would also agree that it looks like cloaking to me too, since this content is hidden from firefox users completely.

I have started another thread about this [webmasterworld.com ] here, since I was thinking that this part of the content was probably hidden from firefox users intentionally using PHP, but now it is becoming even more complected.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved