如何让弹出窗口成为相对大小?

时间:2017-05-11 10:55:06

标签: javascript html popup

我希望外部链接在一个对用户显而易见的过程中在新窗口中打开,因此希望弹出窗口与父窗口的相对大小。最初我只是使用了target属性,但后来开始使用这样的东西:

<a href="http://example.org"  
onclick="window.open(this.href,'window','width=810,height=480,location=0, resizable, scrollbars, toolbar=0, menubar=0') ;return false;">example.org</a>

但我只能使用像素值,我想让弹出窗口的宽度和高度相对于设备的屏幕尺寸(%)。 看起来很简单,但我无法在网上找到任何简单解释如何操作的内容。 有人可以帮忙吗? 提前谢谢。

修改 这是一个样板页面:

<?php 
require("docHead.php"); 
?> this includes everything needed at the head of a document
<title>...</title> varies with the page
</head> 
<body>
<?php 
require("bannerMenu.php"); 
?> navigation etc
<div id="..">
  <div id="..">
        <h1>...</h1>
        <h2>...</h2> 
        Ipsum lorem etc <a href=.....>
        <?php
        require("footer.php"); 
        ?>
  </div>
</div>
</body>    
</html>

2 个答案:

答案 0 :(得分:0)

var testDiv = document.getElementById('test');

testDiv.onclick = function(){
    var xVal = .5 * window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    var yVal = .5 * window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

    window.open('http://google.com','Title','width = ' + xVal + ',' + ' height = ' + yVal );
};

答案 1 :(得分:0)

修改 使用javascript。 window.inner /外部宽度/高度

    <script>
        var features =' width=' + window.outerWidth/2 + ', height=' + window.outerHeight/2 + ',location=0, resizable, scrollbars, toolbar=0, menubar=0';
    </script>

<a href="https://example.org" onclick="window.open(this.href,'window', features) ;return false;">example.org</a>