homepage Welcome to WebmasterWorld Guest from 54.205.144.54
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

    
textContent and innerText vs Google Chrome
can't modify page with javascript
jaruba




msg:3928339
 8:56 pm on Jun 7, 2009 (gmt 0)

i have the next code:

html body related to topic:
-----------
generated in <b><span id="time"> </span></b> seconds<br>
-----------

javascript related to topic:
-----------
<script type='text/javascript'>
var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
var elem = document.getElementById("time");

if(!hasInnerText){
elem.textContent = "0.003 ";
} else{
elem.innerText = "0.003 ";
}
</script>
-----------

They're purpose obviously is to send the time it took for the page to be generated to the top of the page. This code works flawlessly in any browser i tested it in except Google Chrome where the time isn't sent up the page. Any ideas why that might happen?
Thanks in advance.

 

Fotiman




msg:3928599
 1:15 pm on Jun 8, 2009 (gmt 0)

Welcome to WebmasterWorld! I'm not sure what the exact cause is, but it seems to me that this only fails when you have no value within <span id="time"> </span>. Try this instead:

<span id="time">&nbsp;</span>

That seemed to fix it.

jaruba




msg:3928652
 2:37 pm on Jun 8, 2009 (gmt 0)

Thank you for the reply and solution Fotiman, that indeed fixed my problem. Doubt I would of ever figured it out on my own.

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