javascript 除非更改 IE 中的安全设置,否则弹出窗口会以小尺寸打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25776815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
popup window gets opened in small size unless changing the security settings in IE
提问by MaheshVarma
I am using IE 8 I have the following javascript
我正在使用 IE 8 我有以下 javascript
<script type="text/javascript">
function popupWindow(url) {
w = 1026;
h = 760;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
window.location.href="/site/testApps#app=testApp&nav=testNav";
var newWindow = window.open(url, 'windowname', "toolbar=no, location=no, directories=no,
status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+', height='+h+',
top='+top+',left='+left',screenY='+top+', screenX='+left'");
}
</script>
the pop up is opening successfully, But the problem is it is opening with smaller size. i fixed this by changing the security settings in IE as shown below.
弹出窗口成功打开,但问题是它以较小的尺寸打开。我通过更改 IE 中的安全设置来解决这个问题,如下所示。
Can anyone shed light on why this happened? and what is the solution for this problem? with out changing security settings in IE?
任何人都可以解释为什么会发生这种情况?这个问题的解决方案是什么?没有更改 IE 中的安全设置?
UPDATE:we have different environments (dev,test and uat(runs on secure porthttps://)). this issue is happening only if we run with https:// this is working well(the pop up window is opening with proper dimensions) in dev and test env.
更新:我们有不同的环境(开发、测试和 uat(在安全端口 https:// 上运行))。仅当我们使用 https:// 运行时才会发生此问题,这在开发和测试环境中运行良好(弹出窗口以适当的尺寸打开)。
回答by Philip
If it is not necessary to have a new window, I suggest using 'internal popups' (e.g. a large DIV with an iframe inside it). You can let jQuery assign all anchors with a specific classname to get opened in the internal popup.
如果不需要新窗口,我建议使用“内部弹出窗口”(例如,内部带有 iframe 的大 DIV)。您可以让 jQuery 分配具有特定类名的所有锚点以在内部弹出窗口中打开。
A great benefit is that it's cross-browser, privacy settings independent and fully stylable.
一个很大的好处是它是跨浏览器的,隐私设置独立且完全可样式化。
This also works great against popupkillers, since there is no real popup to detect.
这也适用于 popupkillers,因为没有真正的弹出窗口可以检测。
Simple example:
简单的例子:
$("a.internal-popup").click(function() {
// load href-URL in iframe
$("#popup-iframe").attr("src", $(this).attr("href"));
// show popup-DIV
$("#popup-frame").show();
// prevent the original click
return false;
});
<a href="site.html" class="internal-popup">Link</a>
<div id="popup-frame">
<iframe src="" id="popup-iframe" name="popup-iframe"></iframe>
</div>
Don't forget to add a close button in the popup DIV
不要忘记在弹出的 DIV 中添加关闭按钮
See it in action here: http://jsfiddle.net/PhilQ/ctnqk1Lb/
在这里查看它的实际效果:http: //jsfiddle.net/PhilQ/ctnqk1Lb/
回答by Class
try changing the following
尝试更改以下内容
var newWindow = window.open(myURL, 'windowname', "toolbar=no, location=no,
directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes,
copyhistory=no, width='+w+', height='+h+', top='+top+',left='+left',
screenY='+top+', screenX='+left'");
to the following because the variables aren't used instead they are rendered literally as top='+top+'
到以下,因为变量没有被使用,而是从字面上呈现为 top='+top+'
var newWindow = window.open(myURL, 'windowname', "toolbar=no, location=no,
directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes,
copyhistory=no, width=" + w + ", height=" + h + ", top=" + top + ",
left=" + left + ", screenY=" + top + ", screenX=" + left);
also you can notice in that the color of the variables is back and not red for indication of text like the original one.
您还可以注意到,变量的颜色又回来了,而不是像原始文本一样指示文本的红色。
回答by Amit Pathak
Use this code for the popup to open
使用此代码打开弹出窗口
jQuery(".Popup").dialog({
autoOpen: false,
height: 385, width: 580,
minheight: 165, minwidth: 460,
modal: false,
buttons: {
"Close": function () {
jQuery(this).dialog("close");
}
}
});
and call this jQuery
function:
并调用此jQuery
函数:
jQuery(".Popup").dialog("open")
回答by dxwell
The cause of the issue is that the setting "Allow script-initiated windows without size or position constraints" is disabled by default in IE8.
问题的原因是在 IE8 中默认禁用设置“允许没有大小或位置限制的脚本启动窗口”。
Go to Internet Options | Security Tab | Internet - click on the "Custom" button then scroll to the Miscellaneous section. See the option "Allow script-initiated windows without size or position constraints". When this is set to disabled, any link that calls a JavaScript function that opens a new window will not be able to resize or position the pop-up window.
转至 Internet 选项 | 安全选项卡 | Internet - 单击“自定义”按钮,然后滚动到其他部分。请参阅选项“允许没有大小或位置限制的脚本启动窗口”。当此项设置为禁用时,任何调用打开新窗口的 JavaScript 函数的链接都将无法调整弹出窗口的大小或位置。
Change this setting to "Enable" and the window will resize and position correctly.
将此设置更改为“启用”,窗口将正确调整大小和位置。
回答by Tony Chiboucas
Implicit Globals
隐式全局变量
your w and h variables are set as globals. change those to lines to:
您的 w 和 h 变量被设置为全局变量。将这些行更改为:
var w = 1026;
var h = 760;
Order of operation
操作顺序
Your code sets window.location.href
prior to the newWindow = window.open()
call, depending on the specific win/ie environment, anything after setting the location.href value may have unpredictable results.
instead:
您的代码window.location.href
在newWindow = window.open()
调用之前设置,取决于特定的 win/ie 环境,设置 location.href 值后的任何内容都可能产生不可预测的结果。
反而:
var newWindow = window.open(...);
window.location.href = "...";
String Concatenation issue:
字符串连接问题:
In the third argument to window.open, you started the string with a double-quote, then went to escape it with single-quotes. Use this instead, do not include CRLF's in the actual string:
在 window.open 的第三个参数中,你用双引号开始字符串,然后用单引号转义它。改用它,不要在实际字符串中包含 CRLF:
window.open('about:blank', 'windowname', 'toolbar=no, location=no, directories=no,
status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no,
width='+ w +', height='+ h +', top='+ top +',left='+ left +',
screenY='+ top +', screenX='+ left
);
IE Security
浏览器安全
Because popups were (and still are) so widely abused, IE may ignore some window parameters when using window.open()
.
因为弹出窗口曾经(现在仍然)被如此广泛地滥用,IE 在使用window.open()
.
- MSDN window.open method
- See, "Return Values" Section, and, "Remarks."
- MSDN Understanding Protected Mode in IE
- See all 3 bullets in, "Introducing Protected Mode."
- MSDN window.open 方法
- 请参阅“返回值”部分和“备注”。
- MSDN 了解 IE 中的保护模式
- 查看“介绍保护模式”中的所有 3 个项目符号。