a标签属性 rel=noopener noreferrer

前端之家收集整理的这篇文章主要介绍了a标签属性 rel=noopener noreferrer前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

当你浏览一个页面点击一个a标签链接跳转到另一个页面时,

Crayon-5c891c9b2f02f147350340" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
百度

在新打开的页面(http://www.baidu.com)中可以通过 window.opener 获取到源页面的部分控制权,即使新打开的页面是跨域的也照样可以(例如 location 就不存在跨域问题)。

rel=noopener 新特性

Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891c9b2f038242502235-1">1
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891c9b2f038242502235-1">Crayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"http://www.baidu.com"Crayon-h"> Crayon-v">targetCrayon-o">=Crayon-s">"_blank"Crayon-h"> Crayon-v">relCrayon-o">=Crayon-s">"noopener noreferrer"百度Crayon-o"><Crayon-o">/Crayon-v">a

在 Chrome 49+,Opera 36+,打开添加了 rel=noopener 的链接, window.opener 会为null。在老的浏览器中,可以使用 rel=noreferrer 禁用HTTP头部的Referer属性,使用下面JavaScript代替 target=’_blank’ 来解决此问题:

Crayon-5c891c9b2f03b813574988" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">JavaScript
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891c9b2f03b813574988-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9b2f03b813574988-2">2
Crayon-num" data-line="Crayon-5c891c9b2f03b813574988-3">3
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891c9b2f03b813574988-1">Crayon-t">varCrayon-h"> Crayon-v">otherWindowCrayon-h"> Crayon-o">=Crayon-h"> Crayon-v">windowCrayon-sy">.Crayon-e">openCrayon-sy">(Crayon-s">'http://www.baidu.com'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891c9b2f03b813574988-2">Crayon-v">otherWindowCrayon-sy">.Crayon-v">openerCrayon-h"> Crayon-o">=Crayon-h"> Crayon-t">nullCrayon-sy">;
Crayon-line" id="Crayon-5c891c9b2f03b813574988-3">Crayon-v">otherWindowCrayon-sy">.Crayon-v">locationCrayon-h"> Crayon-o">=Crayon-h"> Crayon-v">urlCrayon-sy">;

使用 window.open 打开页面,手动将 opener 设置为 null。

原文链接:https://www.f2er.com/wordpress/238336.html

猜你在找的wordpress相关文章