同一窗口单击时调整大小

时间:2015-03-03 08:53:53

标签: javascript html css

我在页面内部有一个链接,它会显示一个带有一系列链接的浮动窗口。

<a href='javascript:void(0);' onclick='window.open("http://mylink.html","ZenPad","width=150, height=900");' target='ZenPad'><img src=http://mygraphic.png></a>

页面上的链接(下面示例中的编码)但是当点击时,它们出现在弹出的同一窗口中,但窗口保持原来设置为w150和h900的大小,除非你抓住侧面和拖着它。有没有办法让窗口调整大小以适应链接在同一窗口中的页面尺寸?以下是我编码的一个例子。

<a href='javascript:void(0);' onclick='window.open("http://mylink.html","ZenPad","width=850, height=600");' target='ZenPad'><img src=http://myimg.png><br><font color="#34a6a7"></a>WHOCHAT</font><br><br>

编辑以显示我的编码:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>ReVo Links</title>
<SCRIPT LANGUAGE="JavaScript">
function newWindow(){
var windowWidth = 850;
var windowHeight = 600;
var xPos = (screen.width/2) - (windowWidth/2);
var yPos = (screen.height/2) - (windowHeight/2);
window.open("http://mywebpage.com","ZenPad","width=" 
+ windowWidth+",height="+windowHeight +",left="+xPos+",top="+yPos);
}
</script>
<body text="#FFFFFF" bgcolor="#000000">
<center><br>
<a href='javascript:void(0);' onclick='newWindow()' target='_blank'><img src=http://mygraphiclink.png><br><font color="#34a6a7"></a>WHOCHAT</font><br><br>

(这里还有其他链接需要做同样的事情,只需测试第一个链接就能使它工作)

</body>
</html>

1 个答案:

答案 0 :(得分:0)

替换function的onclick并设置target="_blank"以打开新的寡妇:

<a href='javascript:void(0);' onclick='newWindow()' target='_blank'><img src=http://myimg.png><br><font color="#34a6a7"></a>WHOCHAT</font><br><br>

并创建打开新窗口的功能(这将在屏幕和个人大小的中心):

function newWindow(){
    var windowWidth = 850;
    var windowHeight = 600;
    var xPos = (screen.width/2) - (windowWidth/2);
    var yPos = (screen.height/2) - (windowHeight/2);
    window.open("http://mylink.html","ZenPad","width=" 
    + windowWidth+",height="+windowHeight +",left="+xPos+",top="+yPos);
}
相关问题