如果我的理解正确,听起来像:
- 您在 HTML 页面的中心有一个小型 Flex 应用程序
- 在某些情况下,您想创建一个 HTML 弹出窗口(新的浏览器弹出窗口)。
- 该弹出窗口应位于 HTML 页面的中心。
如果正确,则不需要使用 localToGlobal 或 globalToLocal;您只是在寻找浏览器视口范围。这是我目前用来放置与浏览器边界相关的项目的方法(所有这些都是 javascript):
function getBrowserBounds()
{
var size = [0, 0];
if (typeof window.innerWidth != "undefined") {
size = [window.innerWidth, window.innerHeight];
}
else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
}
else {
size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
}
var bounds = null;
if (navigator.userAgent.indexOf("MSIE") != -1) // Internet Explorer
bounds = [window.screenLeft, window.screenTop, size[0], size[1]];
else
bounds = [window.screenX, window.screenY, size[0], size[1]];
var width = bounds[0] + (bounds[2]/2);
var height = bounds[1] + (bounds[3]/2);
return bounds;
}
返回浏览器视口的边界。从那里,您可以创建一个位于浏览器中心的弹出窗口,无论浏览器在笔记本电脑/台式机屏幕范围内的任何位置,使用以下命令:
function centerPopup(windowHeight, windowWidth, windowName, windowUri)
{
var bounds = getBrowserBounds();
var centerWidth = bounds[0] + ((bounds[2] - windowWidth) / 2);
var centerHeight = bounds[1] + ((bounds[3] - windowHeight) / 2);
newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);
newWindow.focus();
return newWindow.name;
}
让我知道这是否有效。
最好,
兰斯