javascript 打开后如何从主页调整弹出窗口的大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7036877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resize popup window from the main page after opening it?
提问by Sarath
I have opened a poup up window with a specific width,height ,top,left.
我打开了一个具有特定宽度、高度、顶部、左侧的弹出窗口。
var newwindow=window.open("one.html",'name','height=200,width=650,top=300,left=100');
After 5 seconds i need to change the width,height,top,left of the popup window from a setInterval function in the main page. how can i do that.?
5 秒后,我需要从主页中的 setInterval 函数更改弹出窗口的宽度、高度、顶部、左侧。我怎样才能做到这一点。?
回答by anupam
This code must be in child window
此代码必须在子窗口中
function calledOnBodyLoad(){
setTimeout(resize_now, 6000);
}
function resize_now(){
window.moveTo(new_posx,new_posxy);
window.resizeTo(newSizeX, newSizeY);
}
If you want to control the pop up window from the parent window then use the following (in parent window)
如果要从父窗口控制弹出窗口,请使用以下(在父窗口中)
////
var newwindow=window.open("one.html",'name','height=200,width=650,top=300,left=100');
setTimeout(resize_now, 6000);
///
function resize_now(){
newwindow.moveTo(new_posx,new_posxy);
newwindow.resizeTo(newSizeX, newSizeY);
}
Remember in this case newwindow
must be a global variable or pass it as a arguement to the resize_now
function.
请记住,在这种情况下newwindow
必须是全局变量或将其作为参数传递给resize_now
函数。
回答by Shamim Hafiz
Inside the OnLoad
function of one.html
, add a timer function that will get executed after five seconds. Make the necessary changes in that function.
在 的OnLoad
函数内one.html
,添加一个将在五秒后执行的计时器函数。在该函数中进行必要的更改。