I'm trying to create a simple pop-up window using this JS code:
window.open(this.href,"popupwindow", "width=400,height=545,innerHeight=500, left=200,top=5,scrollbars,toolbar=0,resizable");
The resultant pop-up window is showing different heights for different browsers. I checked the window.innerHeight through console on different browsers, and this is the result:
safari: window.innerHeight= 455
chrome: window.innerHeight= 500
IE: window.innerHeight= 549
Firefox: window.innerHeight= 544
Here is the JSFiddle link.
I need the pop-up with the height of 500px. How can I do that across all browsers.
Resizing the window after opening may achieve better size accuracy:
var win = window.open("about:blank" "popupwindow", // about:blank for demo
"width=400,height=500,left=200,top=5,scrollbars,toolbar=0,resizable");
// adjust size;
win.resizeBy( 400 - win.innerWidth, 500-win.innerHeight);
requests a window 400 x 500 pixels and then resizes the content area to make sure. Treatment or even recognition of innerHeight and width settings may differ between browsers.
However
Popup windows are subject to user preferences and popup blockers. For example I have IE set to open popups in a new tab (the code above does not open a new window), Firefox to always include the location bar, and regard any site that sets out to circumvent a popup blocker as malicious. You may wish to draw this to the attention of those setting the requirements.
window.open(this.href,"popupwindow", "width=400,innerHeight=500,left=200,top=5,scrollbars,toolbar=0,resizable");
You can't predict the height of window. It's depends on user preferences.
But you only need the innerHeight
Related
I am showing alert on this. But alert is clipped on the either sides, width of popup is 320px. How can I display the entire alert ?Pop-up screen
That problem occurs when Chrome is running on Windows 7. It occurs when alert is smaller than 370px. I have the same problem and I found that it is a bug in Chrome when is used on Windows 7.
In your screenshot the popup is cropped to the parent window size.
Resize the window to show the full alert box.
In all browsers I know the alert-box is always a child of the browser window, so it can never reach outside the browser window.
Option 1
You could use JS to resize the browser window (e.g. make window wider before alert, smaller again after alert):
window.resizeTo( width, height );
Option 2
Create your own JS popup box instead of using alert(). You cannot style the alert() box, but you can control size/design of a custom popup you create
I have a Google Chrome Extension which uses a background process to pop a browser window.
This works OK except for when I have Dual monitors.
Chrome is running on monitor 2. The popup however always occurs on monitor 1 (I want it to open on the monitor where chrome is running).
not matter what I do with window.open parameters it still opens on monitor 1.
You can see in my code I've tried forcing the left to 2000 as an experiment (monitor 1 is 1366 wide). It goes to the right-corner of monitor 1 no matter how high this setting is.
var ilinkWindow = window.open("popup.html", "extension_popup", "width=300,height=500,status=no,scrollbars=yes,resizable=no,top=0,left=2000");
ilinkWindow.focus();
as #wOxxOm says use chrome.windows.create.
That worked for me.
I am building a Chrome extension that will present some stats in a popup window after clickig. I was wondering if it is possible to place a button/icon in the middle on the right edge of Chrome browser (not on the upper tab), so that after clicking a new tab/bar with statistics will slide from right/appear (height of a window should be equal to height of a browser window).
Is it possible? If not how about Chrome App ?
Thanks,
Tomasz
I am trying to refer to window.top in my popup window here http://www.globalrph.com/davescripts/popup.htm
once in the popup I want to access the main window's document but window.top is returning undefined.
To access your popup's opener use.
window.opener
To access your opener's top (e.g your opener is in an iframe)
window.opener.top
Once at the opener window you want you can access the document to change its context, the location to manipulate the URL etc.
If you want to move your popup to the same top position as the opening browser window and centered horizontally to the size of the opening browser window, in modern browsers you can use:
window.moveTo(window.opener.screenX + (window.opener.outerWidth / 2) - (window.outerWidth / 2), window.opener.screenY)
outerWidth and screenX and screenY work in IE9 and above and in modern browsers.
moveTo has been around a long time.
In this case we're getting the left position of the opening browser window, calculating its center and subtracting half the width of the popup. That gives the center position. Then we use window.opener.screenY to get the top position of the opening browser window and setting the popup's top the same.
Many browsers have popup blockers turned on by default and will require the user to click a link to open a popup. I have this web application that opens a popup window to preview the results. A lot of web applications use a positioned div for dialogs. Not knowing your application, I really can't give advice as to the best approach to take.
window.open() of javascript, it is working fine in other browsers, but in case of ie-8 it shows some error such as popup.
You're probably getting stopped by the pop-up blocker.
window.open ("http://www.location.com", "mywindow","status=1,toolbar=1");
The allowed parameters are as below
status The status bar at the bottom of the window.
toolbar The standard browser toolbar, with buttons such as Back and Forward.
location The Location entry field where you enter the URL.
menubar The menu bar of the window
directories The standard browser directory buttons, such as What’s New and What’s Cool
resizable Allow/Disallow the user to resize the window.
scrollbars Enable the scrollbars if the document is bigger than the window
height Specifies the height of the window in pixels. (example: height=’350′)
width Specifies the width of the window in pixels.
(Shamelessly copied from here)