Html 何时使用 target="_self"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15771047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When to use target="_self"
提问by talles
When does the _self
frame targetbecomes useful or worth using it?
_self
框架目标何时变得有用或值得使用?
Isn't it (always?) the default behavior?
它不是(总是?)默认行为吗?
回答by Adrian
The default can be changed by using the <base>
tag in the <head>
:
可以使用 中的<base>
标记更改默认值<head>
:
<base href="http://www.mysite.com/" target="_blank"/>
In this case, you can use target="_self"
on a link to override the target
set by base
.
在这种情况下,您可以target="_self"
在链接上使用来覆盖target
由base
.
回答by parxier
_self
target value could also be useful in conjunction with AngularJS's HTML5 location mode when you do need to force full page reload for links with the same base as your single page app.
_self
当您确实需要为与单页应用程序具有相同基础的链接强制重新加载整页时,目标值也可能与 AngularJS 的 HTML5 位置模式结合使用。
https://docs.angularjs.org/guide/$location#html-link-rewriting
https://docs.angularjs.org/guide/$location#html-link-rewriting
In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.
Links that contain target element Example:
<a href="/ext/link?a=b" target="_self">link</a>
...
在以下情况下,链接不会被重写;相反,浏览器将执行完整页面重新加载到原始链接。
包含目标元素的链接示例:
<a href="/ext/link?a=b" target="_self">link</a>
...
回答by sugardaddy
<base target="_self"/>
Was very handy for me when I had a page I wanted to load into Firefox's sidebar. I wanted any links clicked to stay in the sidebar instead of opening the links in the main window. Adding the above to the <head>
fixed me right up and all the page's links stay within the sidebar.
当我有一个页面想要加载到 Firefox 的侧边栏时,这对我来说非常方便。我希望任何点击的链接都留在侧边栏中,而不是在主窗口中打开链接。将上述内容添加到<head>
固定的 me 中,所有页面的链接都保留在侧边栏中。