Cannot access document's title element with jQuery (IE 8)

后端 未结 2 438
甜味超标
甜味超标 2021-01-18 02:24

I\'m seeing this issue in Internet Explorer 8, but not in Safari or Firefox. So far, I have not tested in other IE versions.

I am developing my own jQuery plugin an

相关标签:
2条回答
  • 2021-01-18 03:10

    try using $('title').html() which should work in all browsers

    0 讨论(0)
  • 2021-01-18 03:11

    I guess jQuery iterates over all TextNodes and concatenates its nodeValue. IE stores this value differently than other browsers.

    var title = document.getElementsByTagName('title')[ 0 ];
    title.firstChild // This would be the Text-Object with the characterdata of the title
                     // Firefox: [object Text]
                     // IE: null
    

    This should be the reason you cannot get the textContent with jQuery.text(). title.text seems to be cross browser comp. I only tested it in IE 7 and Firefox 3.6 but you can check the other browser if you like. But why not using document.title?

    0 讨论(0)
提交回复
热议问题