最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Summernote always open link in new tab - Stack Overflow

programmeradmin0浏览0评论

When users are inserting a link with Summernote, it gives them the option of whether the link should open in a new tab or not. How can I force the user to always choose open a link in a new tab? Even just being able to hide that option would be useful becuase I could add in target="_blank" on the server side. Either way, I have been trying many things but I haven't been able to find an answer.

/

Thanks

When users are inserting a link with Summernote, it gives them the option of whether the link should open in a new tab or not. How can I force the user to always choose open a link in a new tab? Even just being able to hide that option would be useful becuase I could add in target="_blank" on the server side. Either way, I have been trying many things but I haven't been able to find an answer.

http://summernote/

Thanks

Share Improve this question asked Jul 16, 2016 at 18:20 Zach PZach P 57010 silver badges30 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 4

I am not familiar with Summernote, there should be an option in the API to disable that but if you're looking for a quick solution, you can target the option through CSS and hide it.

CSS hiding:

.note-editor .link-dialog .checkbox { display: none; }

However I think it will remain the default state (unchecked), to force it to be checked you'll need JavaScript.

Force check with JavaScript:

document.querySelector('.note-editor .link-dialog .checkbox input').checked = true;

Go to the summernote.js file and find

$openInNewWindow.prop('checked', linkInfo.isNewWindow);

Set this forcefully true by replacing the linkInfo.isNewWindow.

$openInNewWindow.prop('checked', true);

Hopefully it will resolve your issue.

You can use linkTargetBlank: false option to disable default checked on the checkbox.

Like this:

$('.wysiwyg').summernote({
    linkTargetBlank: false
});

See the pull request on github: https://github./summernote/summernote/pull/2195

When you're using Summernote v0.8.11 just go to the summernote.js file and set isNewWindow: true to true instead of $openInNewWindow.is(':checked'). It's around line 6219.

$openInNewWindow.prop('checked', isNewWindowChecked);
$linkBtn.one('click', function (event) {
  event.preventDefault();
  deferred.resolve({
      range: linkInfo.range,
      url: $linkUrl.val(),
      text: $linkText.val(),
      isNewWindow: $openInNewWindow.is(':checked') // change this
  });
  _this.ui.hideDialog(_this.$dialog);
});

You can just set the class .sn-checkbox-open-in-new-window with pointer events set to none. by default it is set to open in new window, so you just make the checkbox unclickable

.sn-checkbox-open-in-new-window{
   pointer-events:none !important
}
发布评论

评论列表(0)

  1. 暂无评论