1

要在新选项卡中打开链接,请执行以下操作:

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

但是我怎样才能让它在新窗口中打开呢?

所以,帮我解决这个问题。

4

7 回答 7

1

我想你想在点击一个链接时打开一个全新的窗口。换句话说,你想要一个弹出窗口。试试下面的代码。

<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>
于 2013-10-28T11:59:36.083 回答
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>
于 2013-10-28T22:20:31.853 回答
1

这在理论上可行,但取决于浏览器中设置的首选项。现在有一天,您可以使用 div 和图层来伪造一个新窗口。无论如何要实现一个隐藏其背后内容的层。

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;边距顶部:-7.8125em;左边距:-12.5em;显示:无;溢出:自动;边框颜色:#000; 边框样式:山脊;边框宽度:中等;z指数:3;颜色:#000;} #close {border-bottom:插图厚#CCC; 背景颜色:#000;宽度:继承;高度:1.2em;颜色:#FFF;位置:固定;} #close 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 {文本对齐:右;填充:1 1 1 1;宽度:10%;明确:正确;浮动:对;背景颜色:#000;颜色:#FFF;}

于 2013-10-28T12:15:40.407 回答
0

使用下面的代码 myWindow=window.open(' https://www.google.co.in/ ','','width=500,height=500');

于 2013-11-20T05:02:24.920 回答
0

如果您在调用时指定宽度和高度window.open,大多数浏览器将在新窗口而不是选项卡中打开链接。

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

现场演示

于 2013-10-28T11:59:55.857 回答
0
<script>
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.focus();
}
</script>

在这里参考更多

于 2013-10-28T11:49:05.190 回答
-2

target="_blank"在“a”标签内使用

于 2013-10-28T12:00:33.033 回答