简体   繁体   English

调整使用window.open创建的窗口的大小

[英]Resizing window which is created using window.open

I have a window which opens when the user clicks a link. 我有一个窗口,当用户单击链接时打开。

echo "<a href=\"javascript:void(0);\" onclick=\"javascript:window.open('https://domain.com/page.php', 'windowName'); \" >Open Window</a>";

When this link is clicked, the page, page.php will be opened. 单击此链接后,将打开页面page.php Now I want to resize the window by providing height, width, top and left parameters. 现在,我想通过提供高度,宽度,顶部和左侧参数来调整窗口大小。 I know it is possible by sending them as third parameter of window.open function. 我知道可以通过将它们作为window.open函数的第三个参数发送来实现。 But I want to do it in page.php file using jquery/javascript. 但是我想使用jquery / javascript在page.php文件中做到这一点 I tried with the following code: 我尝试使用以下代码:

$( document ).ready(function() {
    $(window).resize(function() {
     alert("here");
      $(window).css({
        top: <?php echo $top;?>,
        left: <?php echo $bottom;?>
      });
    });
});

But when the page.php opens, it is not alerting anything also it is not getting resized. 但是,当page.php打开时,它不会发出任何警报,也不会调整大小。 What I'm doing wrong? 我做错了什么? Can anyone please help me to fix this? 谁能帮我解决这个问题?

Thanks in advance. 提前致谢。

On any page, when you bind a resize() event, it will be only get triggered on resizing the window. 在任何页面上,当您绑定resize()事件时,只会在调整窗口大小时触发该事件。

You should try something like this: 您应该尝试这样的事情:

 $(document).ready(function () {
    $(window).resize(function () {
       windowResize(); // Triggered when window resized
    });
    windowResize(); // Triggered when page loaded
 });
 function windowResize() {
    alert("here");
    $(window).css({
       top: <?php echo $top;?>,
       left: <?php echo $bottom;?>
    });
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM