Welcome to WebmasterWorld Guest from 54.167.188.64

Forum Moderators: open

Message Too Old, No Replies

textContent and innerText vs Google Chrome

can't modify page with javascript

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

New User

5+ Year Member

joined:May 12, 2009
posts: 21
votes: 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.

1:15 pm on June 8, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4993
votes: 14


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.

2:37 pm on June 8, 2009 (gmt 0)

New User

5+ Year Member

joined:May 12, 2009
posts:21
votes: 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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members