I'm sorry if this question has been asked before,
I'm just curious with my code:
function showPopup(file,wdth,hght) {
//height = 768 width = 1024
var w = wdth;
var h = hght;
var winWidth = w+'px';
var winHeight = h+'px';
var winTop = (screen.height/2)-(h/2);
var winLeft = (screen.width/2)-(w/2);
window.open(file,'Upload','top='+winTop+',left='+winLeft+',width='+winWidth+',height='+winHeight+',toolbar=1,resizeable=1,statusbar=1,scrollbar=1,location=1, fullscreen=1');
}
Then I run it with HTML:
<input type="button" onClick="showPopup('preview.php', '1000', '1000')" value="Priview">
The opening window still donsn't have toolbar, statusbar, scrollbar, etc as I set inside my function.
Anybody help me what's wrong with my code? Thx
asked Mar 15, 2013 at 4:00
Plipus Tel
7543 gold badges13 silver badges25 bronze badges
2 Answers 2
<html>
<head>
<title>Test Website</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function showPopup(file,wdth,hght) {
//height = 768 width = 1024
var w = wdth;
var h = hght;
var winWidth = w;
var winHeight = h;
var winTop = (screen.height/2)-(h/2);
var winLeft = (screen.width/2)-(w/2);
window.open(file,'Upload','top='+winTop+',left='+winLeft+',width='+winWidth+',height='+winHeight+',toolbar=1,resizeable=1,statusbar=1,scrollbar=1,location=1, fullscreen=1');
}
</script>
</head>
<body>
<input type="button" onClick="showPopup('preview.php', '500', '500')" value="Priview">
</body>
</html>
answered Mar 15, 2013 at 4:05
Paul Calabro
1,9261 gold badge17 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
9 Comments
Plipus Tel
Thank you Paul.. I've try to remove 'px' from the units and try following you code, but it dosen't work. Where is exactly my wrong code? Make me frustated
Paul Calabro
Glad to help. The code above (edited) works perfectly for me! (tested in FF and Chrome)
Paul Calabro
Just found the following accepted answer in another SO post: Unfortunately Chrome only supports a small set of window features when using window.open. If you believe that this is a bug or an issue you can file it at crbug.com. (stackoverflow.com/questions/2568064/…)
Paul Calabro
Just found this for FF in a related SO post: This should do it: window.open("example.com", "name", "scrollbars=1,width=100,height=100"); but note that Firefox will only show scrollbars when the content is larger than the window. To force Firefox to always show a scrollbar (like Internet Explorer does) you need this in the stylesheet of the HTML that's being shown in the popup: html { overflow: -moz-scrollbars-vertical; } (stackoverflow.com/questions/1163275/…)
Paul Calabro
Another SO post saying that FF disabled adjusting the statusbar: stackoverflow.com/questions/2909645/… ... it honestly seems like the cross browser support might be iffy for this.
|
the second parameter ('name') is 'Upload' - it should be '_blank'
or one of the other supported values mentioned here: http://www.w3schools.com/jsref/met_win_open.asp
Paul Calabro is also right, you do not need the "px" units.
Comments
default
console.logwill output to that console.