a標籤target屬性仔細審題

a標籤target屬性仔細審題

咱們來看msdn對於a標籤target的描述html

  • Specifies where to display the linked URL. It is a name of, or keyword for, a browsing context: a tab, window, or <iframe>. The following keywords have special meanings:windows

    • _self: Load the URL into the same browsing context as the current one. This is the default behavior.
    • _blank: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead.
    • _parent: Load the URL into the parent browsing context of the current one. If there is no parent, this behaves the same way as _self.
    • _top: Load the URL into the top-level browsing context (that is, the "highest" browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this behaves the same way as _self.

翻譯一下,就是該屬性能夠指定在什麼地方展現咱們的連接頁面。該屬性值能夠是瀏覽器上下文好比說 tab window或者 iframe的名字,或者關鍵詞.下面有幾個關鍵字具備特殊含義瀏覽器

  • _self: 在本上下文下直接加載連接, a標籤的默認行爲
  • _blank: 在一個新的瀏覽器上下文中打開連接,基本上是個新tab
  • _parent: 該上下文的父上下文中加載連接,若是該上下文不是iframe,行爲跟_self一致
  • _top: 該上下文的頂部上下文中加載連接,若是該上下文不是iframe,行爲跟_self一致

白話描述一下,框架

target的值你能夠指定iframename 或者windowname, 一個隨意的值,或者那四個特殊關鍵字this

指定name將在 iframe中加載,
示例:url

<a href="https://www.baidu.com" target="iframename">iframename</a>
<iframe name="iframename"></iframe>

指定windowname翻譯

<a href="https://www.baidu.com" target="windowname">windowname</a>
<script>
window.open('', 'windowname', '_blank');
</script>

指定隨意一個關鍵字操做相似指定windowname
新開一個tab頁,並在裏面直接加載新連接code

_self的狀況下,就是在當前tab直接打開htm

_blank是不管如何新開一個tabip

_parent是有父框架,好比iframe上層,直接刷新iframe宿主頁面

_top是當有祖先框架的時候,狀況就是 tab頁裏有iframe套iframe的狀況,子孫iframe的 a標籤設置了_top,祖先tab頁被加載新url

相關文章
相關標籤/搜索