diff --git a/docs/configuration.md b/docs/configuration.md index 786bd971c..bcbe2e0de 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -418,6 +418,19 @@ window.$docsify = { }; ``` +## externalLinkRel + +- type: `String` +- default: `noopener` + +Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`. + +```js +window.$docsify = { + externalLinkTarget: '' // default: 'noopener' +}; +``` + ## routerMode - type: `String` diff --git a/src/core/config.js b/src/core/config.js index 0d2139395..f77773726 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -27,6 +27,7 @@ export default function () { externalLinkTarget: '_blank', // this config for the corner cornerExternalLinkTarget: '_blank', + externalLinkRel: 'noopener', routerMode: 'hash', noCompileLinks: [], relativePath: false diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 354b6a920..2f7ce1528 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -78,6 +78,7 @@ export class Compiler { this.toc = [] this.cacheTOC = {} this.linkTarget = config.externalLinkTarget || '_blank' + this.linkRel = this.linkTarget === '_blank' ? (config.externalLinkRel || 'noopener') : '' this.contentBase = router.getBasePath() const renderer = this._initRenderer() @@ -185,7 +186,7 @@ export class Compiler { _initRenderer() { const renderer = new marked.Renderer() - const {linkTarget, router, contentBase} = this + const {linkTarget, linkRel, router, contentBase} = this const _self = this const origin = {} @@ -243,6 +244,7 @@ export class Compiler { href = router.toURL(href, null, router.getCurrentPath()) } else { attrs += href.indexOf('mailto:') === 0 ? '' : ` target="${linkTarget}"` + attrs += href.indexOf('mailto:') === 0 ? '' : (linkRel !== '' ? ` rel="${linkRel}"` : '') } if (config.target) {