2014年10月7日 星期二

jQuery 取 title ie8 error

原本很簡單的,不換頁置換title

  1.  //ie8 ok
  2.  var t_title = $("title").html();
  3.  //ie8 ok
  4.  t_title = t_title.replace("old title","new title");
  5.  //ie8 error
  6.  $("title").html(t_title);

在IE8上卻無法執行:
0x8000ffff - JavaScript 執行階段錯誤: 對方法或內容存取發出非預期的呼叫。
在下面的第四行上出現:

  1. append: function() {
  2.       return this.domManip(arguments, true, function( elem ) {
  3.              if ( this.nodeType === 1 ) {
  4. this.appendChild( elem );
  5.              }
  6.       });
  7. },

google了一下後,找到了答案

  1.  $("title").html(t_title);

置換成

  1.  $(document).attr("title", t_title);

參考:男丁格爾

沒有留言:

張貼留言