简体   繁体   中英

How to add HTML tags in Summernote using custom button?

Let's use this simple example from summernote's doc :

var HelloButton = function (context) {
  var ui = $.summernote.ui;

  // create button
  var button = ui.button({
    contents: '<i class="fa fa-child"/> Hello',
    tooltip: 'hello',
    click: function () {
      // invoke insertText method with 'hello' on editor module.
      context.invoke('editor.insertText', "<iframe src=\""+myUrl+ "\"" + "></iframe>");
    }
  });

  return button.render();   // return button as jquery object 
}

This code works good but it displays everything in text inside the editor like this :

<iframe src="http://............"></iframe>

And I would like that it display the iFrame itself.

Any suggestion ?

PS: I'm also using angular summernote, maybe it can help to solve the problem.

Found the solution myself :

      var node = document.createElement('span');
      node.innerHTML = "<iframe src=\""+myUrl+ "\"" + "></iframe>"</iframe>";
      context.invoke('editor.insertNode', node);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM