admin管理员组

文章数量:1289351

I am using IE 8 I have the following 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.

Can anyone shed light on why this happened? and what is the solution for this problem? with out changing security settings in 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.

I am using IE 8 I have the following 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.

Can anyone shed light on why this happened? and what is the solution for this problem? with out changing security settings in 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.

Share Improve this question edited Sep 17, 2014 at 5:28 MaheshVarma asked Sep 10, 2014 at 23:42 MaheshVarmaMaheshVarma 2,1257 gold badges36 silver badges59 bronze badges 7
  • 1 something to do with "…top='+top+',left='+left',screenY='+top+', screenX='+left'" as in the ''s should be "? or change the outer quotes from "'s to ''s? – Class Commented Sep 10, 2014 at 23:49
  • Please show the code from /myURL here. Changing the href will load a new page, and anything after window.location.href is not executed on the original page. Also the variables of the old page are gone. – Teemu Commented Sep 11, 2014 at 5:07
  • @Teemu /site/apps#app=myApp&nav=testNav – MaheshVarma Commented Sep 11, 2014 at 5:36
  • Ehh.. I mean the code in that file. The code you've posted can't open the pop-up, it must e from another page. – Teemu Commented Sep 11, 2014 at 5:38
  • @Teemu <a href="/myPage.jsp?redirect=none" onclick="popupWindow(this.href);return false;">&nbsp;CLICK</a> – MaheshVarma Commented Sep 11, 2014 at 6:07
 |  Show 2 more ments

5 Answers 5

Reset to default 2 +25

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.

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.

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

See it in action here: http://jsfiddle/PhilQ/ctnqk1Lb/

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+'

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.

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(".Popup").dialog("open")

The cause of the issue is that the setting "Allow script-initiated windows without size or position constraints" is disabled by default in 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.

Change this setting to "Enable" and the window will resize and position correctly.

Implicit Globals

your w and h variables are set as globals. change those to lines to:

var w = 1026;
var h = 760;

Order of operation

Your code sets window.location.hrefprior 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:

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('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().

  • MSDN window.open method
    • See, "Return Values" Section, and, "Remarks."
  • MSDN Understanding Protected Mode in IE
  • See all 3 bullets in, "Introducing Protected Mode."

本文标签: javascriptpopup window gets opened in small size unless changing the security settings in IEStack Overflow