HTML中的target(_self,_blank)用法總結


最近一個項目,多次遇到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 是只能在一個網站中打開本網站的網頁

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM