在页面加载时使用javascript(没有jquery)自动调整大小并居中显示窗口 [英] Self resize and center a window using javascript (no jquery) on page load

查看:110
本文介绍了在页面加载时使用javascript(没有jquery)自动调整大小并居中显示窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是我们通常要做的事情,但是我们正在尝试将视频加载到由clickTag(来自横幅广告)打开的空白窗口中,并尽可能使它看起来像是模态窗口。



是否可以使用JavaScript自行调整由clickTag打开的空白窗口的大小并将其居中显示在屏幕上?




  • 我们不能对单击的链接应用任何内容,所以...

  • 一切都必须自运行页面加载

  • 如果可能的话,最好不要看到浏览器选项卡和地址栏

  • 我们没有加载jQuery
  • >
  • 浏览器安全是否在提醒潜在问题?



基本上,用户单击观看视频后,我们会d希望他们观看视频时不会让他们觉得自己去了一个完全不同的网站。



到目前为止,我可以调整窗口大小,但无法弄清楚使其居中:

 < script lan guage = javascript> 

函数resizeVideoPage(){
resizeTo(400,390);
window.focus();
}
< / script>

//然后...

< body onload = resizeVideoPage();>< / body>

向正确方向的任何指针将不胜感激。



欢呼



解决方案

我个人会对Popups的建议是Javascript窗口操作。 (由于弹出窗口阻止程序,Javascript错误,...)覆盖可能会更好。



这里是另一种解决方案。



一个文件(链接应指向此帮助程序,打开视频HTML)

 < html> ; 
< body>
< script>
var windowWidth = 400;
var windowHeight = 200;
var xPos =(screen.width / 2)-(windowWidth / 2);
var yPos =(screen.height / 2)-(windowHeight / 2);
window.open( popup.html, POPUP, width =
+ windowWidth +,height = + windowHeight +,left = + xPos +,top = + yPos );
< / script>
< / body>
< / html>

文件二(关闭助手的视频)

 < html> 
< body onload = window.opener.close();>
< / body>
< / html>


This is not something we'd normally do but we're trying load a video into the blank window opened by a clickTag (from a banner ad) - and make it feel like a modal window as much as possible.

Is it possible to use javascript to self-resize the blank window opened by the clickTag and center it on the screen?

  • We can't apply anything to the link that is clicked so...
  • Everything has to self-run as the page loads
  • If possible, it would be nice to not see the browser tabs and address bar
  • We're not loading jquery
  • Are browser security alerts a potential problem?

Essentially the user clicks to watch a video and we'd like them to watch the video without them feeling like they've gone to a completely different site.

So far I can resize the window but can't figure out how to center it with:

<script language="javascript">

  function resizeVideoPage(){
    resizeTo(400,390);
    window.focus();
  }
</script> 

// Then...

<body onload="resizeVideoPage();"></body>

Any pointers in the right direction would be much appreciated.

Cheers

Ben

解决方案

I personally would advice against Popups an Javascript window manipulation. (due to Popup Blockers, Javascript errors, ...) A Overlay would probably be better.

Here would be an other Solution.

File one(Link should point to this Helper, that opens the Video HTML)

<html>
<body>
<script>
    var windowWidth = 400;
    var windowHeight = 200;
    var xPos = (screen.width/2) - (windowWidth/2);
    var yPos = (screen.height/2) - (windowHeight/2);
    window.open("popup.html","POPUP","width=" 
    + windowWidth+",height="+windowHeight +",left="+xPos+",top="+yPos);
</script>
</body>
</html>

File Two (Video that closes Helper)

<html>
<body onload="window.opener.close();">
</body>
</html>

这篇关于在页面加载时使用javascript(没有jquery)自动调整大小并居中显示窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆