如何在當前窗口的中心打開一個框架?在當前窗口的中心打開一個框架
的JS很簡單:
window.open("http://www.google.com", "activate-frame", "height=600,width=800,centerscreen,chrome=yes");
然而了「中心屏幕」屬性實際上沒有在屏幕的中心開口的框架。
的jsfiddle:http://jsfiddle.net/ecm9bpox/1/
如何在當前窗口的中心打開一個框架?在當前窗口的中心打開一個框架
的JS很簡單:
window.open("http://www.google.com", "activate-frame", "height=600,width=800,centerscreen,chrome=yes");
然而了「中心屏幕」屬性實際上沒有在屏幕的中心開口的框架。
的jsfiddle:http://jsfiddle.net/ecm9bpox/1/
你必須放置窗口在屏幕上之前,計算出屏幕的寬度和高度。
事情是這樣的:
function popupwindow(url, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
popupwindow('http://google.com','Test Frame',600, 800)
As answered here,類似的堆棧溢出後。
目前還不清楚,但根據Mozilla文檔,它可能只適用於chrome腳本。
變種贏得= window.open( 「鉻://myextension/content/about.xul」, 「aboutMyExtension」, 「鉻,中心屏幕」);
第一個參數對window.open是XUL的URI文件描述窗口和其內容。
https://developer.mozilla.org/en-US/docs/Working_with_windows_in_chrome_code