当前位置: 移动技术网 > IT编程>网页制作>CSS > HTML中的target(_self,_blank)用法总结

HTML中的target(_self,_blank)用法总结

2019年06月30日  | 移动技术网IT编程  | 我要评论

最近一个项目,多次遇到target='_self', target='_blank'的用法, 再次总结一下:

1.<a>标签

<a href="xxxx"  target="_self">xx</a>

<a href="xxxx"  target="_blank">xx</a>

2.<form>标签

 <form name=alipayment action=alipayapi.jsp method=post target="_blank">  (该代码来自支付宝的demo)

3.window.open

var url =xxxx;
window.open(url,'_self');

(window.location.href=xxx;)

在同一个项目中遇到了target的三种用法。

 

target的所有取值以及它们的含义:

_blank:在新窗口中打开;

_self:默认。在相同的框架中打开;

_parent:在父框架集中打开;

_top:在整个窗口中打开;

其实我们一般很少用到frameset标签,所以一般我们只是经常用到target='_self' 和 target='_blank',分别用于在当前页面打开,和在一个新的页面打开。

在 html 4.01 中,不赞成使用 form 元素的 target 属性;在 xhtml 1.0 strict dtd 中,不支持该属性。

 

window.open与window.location.href的区别:

window.open() 用来打开新窗口,但是加上'_self',可以达到使用window.location.href的效果 
window.location.href 用来替换当前页,也就是重新定位当前页

window.open() 是可以在一个网站上打开另外的一个网站的地址 
而window.location.href 是只能在一个网站中打开本网站的网页

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网