如何从链接vuejs中删除目标属性?

时间:2018-10-08 14:21:50

标签: javascript vue.js vuejs2 quill

我正在使用https://quilljs.com/编辑器,它将目标属性添加到所有链接。我想动态删除所有内容。我在SPA中使用它,所以效果不好。

2 个答案:

答案 0 :(得分:1)

此代码应该起作用。

const targets = document.querySelectorAll('[target]')
targets.forEach(e => {
    e.removeAttribute('target')
})

答案 1 :(得分:1)

重复: https://stackoverflow.com/a/52275503/6809056

您可以扩展链接格式并删除目标属性。 参见此example

var Link = Quill.import('formats/link');

class MyLink extends Link {
  static create(value) {
    const node = super.create(value);
    node.setAttribute('href', this.sanitize(value));
    //node.setAttribute('target', '_blank');
    node.removeAttribute('target');
    return node;
  }
}

Quill.register(MyLink);


var quill = new Quill('#editor-container', {
  modules: {
    toolbar: [
      [{ header: [1, 2, false] }],
      ['bold', 'italic', 'underline'],
      ['link']
    ]
  },
  placeholder: 'Compose an epic...',
  theme: 'snow'  // or 'bubble'
});