1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

  issue on Google Chrome??

Discussion in 'JavaScript' started by lp1051, Mar 12, 2009.

  1. #1

    during fixing one xhtml page, I found very strange behavior of Google Chrome.
    There was a placeholder div containing ' ' only.
    While IE, FF, Opera, Safari gave value of innerHTML as a string (' '), Chrome returned space. That would be OK, but the strange thing is that it is not ordinary space. I mean you cannot use if(the_div.innerHTML == " "), it simply won't evaluate this condition as true. The only way I found around was to use charCodeAt() and check if it's equal 160.

    Maybe I missed something, that's why I'm asking here if you experienced similar problem, or found some explanation. Is it bug on Chrome, or just design?
    I also found similar problem here: http://groups.google.com/group/goog...g/browse_thread/thread/7a7071a886163145?pli=1
    but with no reply....

    Not sure if it's clear what I mean, so here is very basic code sample :
    <div id="d">&nbsp;</div>
    <script type="text/javascript">
     var cont=document.getElementById('d').innerHTML;
     if(cont == '&nbsp;') alert('nbsp');
     if(cont == ' ') alert('space');
     if(cont.charCodeAt() == 160) alert('charCodeAt')
    Code (markup):
    Btw. the same behavior is repro using & # 160;

    Thanks for any ideas, advices.
    lp1051, Mar 12, 2009 IP
  2. lp1051

    lp1051 Active Member

    Likes Received:
    Best Answers:
    Trophy Points:
    I got answer on SitePoint, Google Chrome v.2 doesn't have this problem anymore, so just in the case you will need to evaluate &nbsp;, for compatibility remember charCodeAt()
    lp1051, Mar 12, 2009 IP