admin管理员组文章数量:1202777
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
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
Share Improve this question edited Feb 14, 2013 at 1:42 CMSCSS asked Feb 14, 2013 at 1:35 CMSCSSCMSCSS 2,1769 gold badges28 silver badges50 bronze badges2 Answers
Reset to default 12Got it working with:
<script language="javascript">
function resizeVideoPage(){
var width = 600;
var height = 400;
window.resizeTo(width, height);
window.moveTo(((screen.width - width) / 2), ((screen.height - height) / 2));
}
</script>
// Then...
<body onload="resizeVideoPage();"></body>
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>
本文标签: Self resize and center a window using javascript (no jquery) on page loadStack Overflow
版权声明:本文标题:Self resize and center a window using javascript (no jquery) on page load - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738607535a2102436.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论