2012-03-22 10 views
0

nicedit.js wysiwygライブラリを使用していて、リンクを挿入するボタンに問題があります。IE8: "ln.innerHTMLがヌルかオブジェクトではありません"

ボタンをクリックすると、URLとタイトルを入力して[送信]をクリックするパネルが表示されます。リンクはカーソル位置に挿入する必要があります。しかし、私はIE8で、次のエラーが表示されます。

ln.innerHTMLはnullまたはオブジェクトではありませんどちらかである


エラーラインは次のとおりです。

if (this.ln.innerHTML == tmp) { 


完全なコード

var nicLinkButton = nicEditorAdvancedButton.extend({  
addPane : function() { 
    this.ln = this.ne.selectedInstance.selElm().parentTag('A'); 
    this.addForm({ 
     '' : {type : 'title', txt : 'Add/Edit Link'}, 
     'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}}, 
     'title' : {type : 'text', txt : 'Title'}, 
     'target' : {type : 'select', txt : 'Open In', options : {'' : 'Current Window', '_blank' : 'New Window'},style : {width : '100px'}} 
    },this.ln); 
}, 

submit : function(e) {   

    var url = this.inputs['href'].value; 
    if(url == "http://" || url == "") { 
     alert("You must enter a URL to Create a Link"); 
     return false; 
    } 
    this.removePane(); 

    if(!this.ln) { 
     var tmp = 'javascript:nicTemp();'; 
     this.ne.nicCommand("createlink",tmp); 
     this.ln = this.findElm('A','href',tmp); 
     // set the link text to the title or the url if there is no text selected 
     if (this.ln.innerHTML == tmp) { 
      this.ln.innerHTML = this.inputs['title'].value || url; 
     }; 
    } 
    if(this.ln) { 
     var oldTitle = this.ln.title; 
     this.ln.setAttributes({ 
      href : this.inputs['href'].value, 
      title : this.inputs['title'].value, 
      target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value 
     }); 
     // set the link text to the title or the url if the old text was the old title 
     if (this.ln.innerHTML == oldTitle) { 
      this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value; 
     }; 
    } 
} 

});

このエラーも表示されませんが、nicedit.comホームページの例でもリンクは挿入されません。

答えて

0

Internet Explorerは他のブラウザと同じようにinnerHTMLを処理しません。特に、テーブル要素について話している場合は特にそうです。詳細は、hereを参照してください。

特定の状況に応じて、多くの場合、this suggestionにはさまざまな修正があります。また、IE互換にしたい場合は、innerHTMLを更新するのではなく、テーブル要素を削除して再作成する必要があります。

0

いくつかの簡単な守備のロジックが動作するはずです:

if (!this.ln.innerHTML || this.ln.innerHTML == tmp) { 
     this.ln.innerHTML = this.inputs['title'].value || url; 
    }; 
0

テキストが選択されていないこの問題の昇給を

nicEditのための私のトリックは、テキストが選択されていない状況で、指定されたタイトルを貼り付けることです

「リンクの追加」フォームを使用して文書に挿入して選択すると、残りのコードはテキストが選択されたときに機能します。

私はgetSelectedが

function getSelected() 
{ 
    if (document.selection) 
     return document.selection.createRange().text; 
    else 
     return window.getSelection(); 
} 
次のようにも単純な関数であるのcontentEditableのdivに

var selected = getSelected(); 
if (selected == '') 
    pasteHtmlAtCaret(this.inputs['title'].value,true); 
if(!this.ln) { 
    var tmp = 'javascript:nicTemp();'; 
    this.ne.nicCommand("createlink",tmp); 
    this.ln = this.findElm('A','href',tmp); 
    // set the link text to the title or the url if there is no text selected 
    if (!this.ln.innerHTML || this.ln.innerHTML == tmp) { 
     this.ln.innerHTML = this.inputs['title'].value || url; 
    }; 
} 

をキャレット位置のタイトル

挿入HTMLを貼り付けるには次のリンクで説明した機能pasteHtmlAtCaretを使用

関連する問題