2012-01-27 112 views
2

我想打開一個彈出窗口,以便它的高度是從屏幕的頂部到Windows的「應用程序」欄。這是代碼:如何打開彈出窗口,使其高度從屏幕頂部到底部?

function windowOpener(windowHeight, windowWidth, windowName, windowUri) { 

var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight; 


var centerWidth = (window.screen.width - windowWidth)/2; 
var centerHeight = (window.screen.height - windowHeight)/2; 


newWindow = window.open(windowUri, windowName, 'resizable=0,scrollbars=1,width=' + windowWidth + 
    ',height=' + windowHeight + 
    ',left=' + centerWidth); 

newWindow.focus(); 
return newWindow.name; 

} 

爲什麼不在IE中工作? (在Chrome瀏覽作品)

感謝

回答

6

我想你只需要screen.width和screen.height。不要把它們放在窗口前面。

編輯:顯然IE需要一個「fullscreen = yes」參數。

試試這個:

<script type="text/javascript"> 
<!-- 
function popup(url) 
{ 
params = 'width='+screen.width; 
params += ', height='+screen.height; 
params += ', top=0, left=0' 
params += ', fullscreen=yes'; 

newwin=window.open(url,'windowname4', params); 
if (window.focus) {newwin.focus()} 
return false; 
} 
// --> 
</script> 

<a href="javascript: void(0)" 
    onclick="popup('popup.html')">Fullscreen popup window</a> 
+0

這確實讓彈出更大!但是,您是否知道如何在「應用程序」欄停下來,在那裏您可以在Windows中看到所有打開的應用程序? – Kenci 2012-01-27 15:38:38

+0

我用一些*真實*代碼編輯了我的答案。 :) – skybondsor 2012-01-27 15:42:22

+0

很酷。它現在可以在Chrome和IE中使用。謝謝! :) – Kenci 2012-01-27 16:04:19

0

如果你只是想在全屏模式下打開新窗口,並嘗試刪除高度和寬度的參數?

newWindow = window.open(windowUri, windowName); 

see reference

1

這個工作對我來說:

<a class="popme" href="http://codesheet.org">popup</a> 

jQuery的

$(document).ready(function() { 
    $(".popme").click(function(event){ 
     var h = 650; 
     var w = 340; 
     var wh = screen.height; 
     var ww = screen.width; 
     var top = wh/2 - h/2; 
     var left = ww/2 - w/2; 
     var popup = window.open(this.href + '', 'player', 'height=' + wh + ', width=' + w + ', scrollbars=no, left=' + left + ', top=' + top); 
     popup.focus(); 
     return false; 
    }); 
    }); 

演示:http://codesheet.org/codesheet/JMbOYCUI

相關問題