2013-10-28 25 views
0

打開新窗口(而不是在新標籤頁)的鏈接,打開新的標籤頁的鏈接,你這樣做:如何在HTML/CSS

<a href="#" target="_blank">open in new tab</a> 

但我怎麼能使其在新窗口中打開?

所以,幫我解決這個問題。

+1

這是非常糟糕的用戶體驗決定如何以及何時打開新窗口(或標籤)。該決定應留給用戶, –

+0

這是答案:http://stackoverflow.com/a/15766254/458614 – tobek

回答

0
<script> 
function openWin() 
{ 
myWindow=window.open('','','width=200,height=100'); 
myWindow.document.write("<p>This is 'myWindow'</p>"); 
myWindow.focus(); 
} 
</script> 

多參考在here

1

我想喲想在點擊link.in換句話說打開一個全新的窗口想要可popup.try下面的代碼。

<script language="javascript" type="text/javascript"> 
function popitup(url) { 
newwindow=window.open(url,'name','height=200,width=150'); 
if (window.focus) {newwindow.focus()} 
return false; 
    } 

<a href="popupex.html" onclick="return popitup('popupex.html')">Link to popup</a> 
0

如果當你調用window.open指定的寬度和高度,大多數瀏覽器會打開一個新的窗口,而不是一個選項卡的鏈接。

window.open(url, '_blank', 'width=500,height=400'); 

Live Demo

-2

使用target="_blank" 「一」 的標籤

0

這工作在理論上,而且它依賴於瀏覽器設置的首選項內。現在有一天你可以使用div和Layers僞造一個新窗口。無論如何要實現一個隱藏它背後的圖層。

的JavaScript:

function getElementsByClass(searchClass, domNode, tagName) { 
    if (domNode == null) domNode = document; 
    if (tagName == null) tagName = '*'; 
    var el = new Array(); 
    var tags = domNode.getElementsByTagName(tagName); 
    var tcl = " "+searchClass+" "; 
    for(i=0,j=0; i<tags.length; i++) { 
    var test = " " + tags[i].className + " "; 
    if (test.indexOf(tcl) != -1) 
     el[j++] = tags[i]; 
} 
return el; 
} 
// paste getElementsByClass function (see above) here 

function showtab(tabname) 
{ 
// hide every element with class 'box1' 
var tabs = getElementsByClass('box1'); 
for(i=0; i<tabs.length; i++) { 
    tabs[i].style.display = 'none'; 
    //tabs[i].style.visibility = 'hidden'; 
} 
// hide every element with class 'box1'  
var tabs2 = getElementsByClass('myStyle'); 
for(i=0; i<tabs2.length; i++) { 
    tabs2[i].style.display = 'none'; 
    //tabs2[i].style.visibility = 'hidden'; 
} 

document.getElementById(tabname).style.display='block'; 
//document.getElementById(tabname).style.visibility='visible'; 
// show element with given tabname 
} 

function showsubtab(tabname) 
{ 
//hide every element with class 'myStyle' 
var tabs = getElementsByClass('myStyle'); 
for(i=0; i<tabs.length; i++) { 
    tabs[i].style.display = 'none'; 
    //tabs[i].style.visibility = 'hidden'; 
} 
document.getElementById(tabname).style.display='block'; 
//document.getElementById(tabname).style.visibility='visible'; 
} 

if (window.addEventListener) { // Mozilla, Netscape, Firefox 
window.addEventListener('load', showmessage, false); 
} else if (window.attachEvent) { // IE 
window.attachEvent('onload', showmessage); 
} 

function showmessage() { 
document.getElementById('box').style.display='block'; 
document.getElementById('div1').style.backgroundColor='grey'; 
document.getElementById('div1').style.opacity = 0.2; 
document.documentElement.style.overflow = "hidden"; //firefox, chrome 
document.body.scroll = "no"; // ie only 
var bodyLayer = document.getElementById('div1'); 
DisableLinks(bodyLayer); 
} 
function hidemessage() { 
document.getElementById('box').style.display='none'; 
document.getElementById('div1').style.backgroundColor='transparent'; 
document.getElementById('div1').style.opacity = 1.0; 
document.documentElement.style.overflow = 'auto'; // firefox, chrome 
    document.body.scroll = "yes"; // ie only 
var bodyLayer = document.getElementById('div1'); 
EnableLinks(bodyLayer); 
} 

function DisableLinks(dom) { 
if(undefined != dom){ 
    links=dom.getElementsByTagName('A'); 
} else { 
    links=document.getElementsByTagName('A'); 
} 

for(var i=0; i<links.length; i++) { 
    links[i].style.pointerEvents="none"; 
} 
} 

function EnableLinks(dom) { 
if(undefined != dom){ 
    links=dom.getElementsByTagName('A'); 
} else { 
    links=document.getElementsByTagName('A'); 
} 

for(var i=0; i<links.length; i++) { 
    links[i].style.pointerEvents="auto"; 
} 
} 

HTML

<div id="box"> 
<section id="close"> 
<section id="title">Important Site Message</section> 
<section id="button"><a href="#" onClick="hidemessage();">[X]</a>&nbsp;</section> 
</section> 
<!--Body of the Message--> 
</div> 

CSS #box {位置:絕對的;頂部:50%;剩下:50%;身高:15.625em;寬度:25em;背景色:#FFF; margin-top:-7.8125em;餘量:-12.5em;顯示:無;溢出:自動;邊框顏色:#000;邊框樣式:脊;邊框寬度:介質; z-index:3;顏色:#000;} #close {border-bottom:inset thick #CCC; background-color:#000;寬度:繼承;身高:1.2em;顏色:#FFF;位置:固定;} #關閉a:visited {color:#FFF;} #close a:hover {color:red; text-decoration:none;} #close #title {text-align:center;字體重量:粗體;寬度:90%;填充:1 1 1 1;清楚:離開;向左飄浮;背景色:#000;顏色:#FFF;} #close #button {text-align:right;填充:1 1 1 1;寬度:10%;清楚:對; float:right; background-color:#000;顏色:#FFF;}

1

嘗試:

<a href="#nul" onclick="window.open('newLink.html ','','Toolbar=1,Location=0,Directories=0,Status=0,Menubar=0,Scrollbars=0,Resizable=0,Width=550,Height=400');">Name</A>