Press "Enter" to skip to content

IE下pre标签的InnerHTML问题

今天在升级我自己的语法高亮显示插件的时候, 发现在IE下, 都缺少了最后一行的显示, 如果pre中只有一行语句的时候, 就什么都不显示..
追踪了半天(IE下我只用Alert,,,), 最后发现, 如下语句在IE上运行的结果, 比在FF/Chrome中少1.

    var codes = document.getElementsByTagName("pre");
    alert(codes[0].length); //IE下如果是10, 那么在FF/Chrome中就是11

因为我的语法高亮插件, 是通过对最后一个字符是否为\n ,或者 \r来判断新行开始, 旧行结束的, 所以导致在IE下, 最后一行的内容永远不会显示..
原来, IE对所有要显示的data都做了text normalization, 即使是pre或者textarea这种应该保持原状的标签, 应该是这个原因, 导致在显示pre内容的时候, 行尾的回合换行被抹掉了.
有这个问题的IE包括: Explorer 6, 7, 8 (已验证)

17 Comments

  1. tetris
    tetris December 31, 2020

    I should express that I like this article so a ton and moreover using it in regular. I believe you would continue sharing better than average article here.

  2. vlc
    vlc December 18, 2019

    vlc player for this

  3. shell shockers
    shell shockers November 28, 2019

    This HTML coding is difficult to understand but after going through this article it has made some sort of easy.

  4. bubble shooter
    bubble shooter September 29, 2019

    有些事情必须很难找到解决方案。

  5. visit here
    visit here August 28, 2019

    such a interesting post

  6. slope
    slope August 5, 2019

    supurb article

  7. run3
    run3 August 5, 2019

    your post really nice

  8. wings.io
    wings.io June 22, 2019

    This topic is very interesting and I am interested but do not know where to find, thankfully you create this topic, hope everyone will help me

  9. Run 3 game
    Run 3 game May 22, 2019

    Thanks for letting us know about this plugging in. Worth sharing and going through post.

  10. assignment代寫
    assignment代寫 February 26, 2019

    首先,您需要了解这种语言的基础知识。毫无疑问,它易于使用,但仍有。

  11. Happy wheels
    Happy wheels December 28, 2018

    Got what I was searching for. Thanks for posting it. Such a help. Thumbs up.

  12. geometry dash lite
    geometry dash lite December 31, 2017

    或者 \r来判断新行开始, 旧行结束的, 所以导致在IE下, 最后一行的内容永远不会显示….

Comments are closed.