Closing child windows onunload event in javascript - javascript

I am working on a project that has an onload event of
var opsWin = window.open ('url','_blank', 'options);
var preWin= window.open ('url','_blank', 'options);
var pkgWin= window.open ('url','_blank', 'options);
var apcWin= window.open ('url','_blank', 'options);
opsWin.focus();
preWin.focus();
pkgWin.focus();
apcWin.focus();
These popups displays 4 different PDFs that the user needs to see before proceeding. My problem comes on my onunload event:
function unLoadDocs(){
alert(opsWin)
opsWin.close();
preWin.close();
pkgWin.close();
apcWin.close();
}
My alert is for debugging purposes, to make sure I make it there and to see that opsWin actually exists(it does make it there and it does exist and in scope). My problem is that the documents are not closing in Internet Explorer 10. I try the same script in Mozilla Firefox, and it works perfectly.
Some insight as to why these windows won't close on Internet Explorer 10 would be great.(I have also tried IE9 with no success)

The popups were PDF's, so adobe reader was holding it open/had a different handle. Ultimately, I opened another window with a 100% width and height i-Frame and embedded the PDF in the i-Frame. I was then able to close the windows with the unload function above.

Related

Window.open doesn't work when original window size is specified

I have a script that opens a chrome window like so chrome.exe --user-data-dir="%LOCALAPPDATA%\Google\Chrome\User Data\" --window-size=1280,118 --window-position=0,0 --app="file:///C:/desktop/test.html" I need to open another smaller popup window from that window but the popup always opens in the same size as its parent (1280x118). I have tested using window.open('','','resizeable, width=100,height=200') from a regular chrome window and it works as expected. It seems that window.open does not respect the width and height specified if it is launched from a window with a specified window-size. Are there any alternatives to window.open? Or does anybody know how to make this work in Chrome? Its working fine in IE but want to phase out IE for obvious reasons.
I made this work by setting window.open to a variable and then using window.resizeTo to change its size.
var myWindow=window.open('','newWin','width=200,height=100');
myWindow.resizeTo(200,300);
myWindow.moveTo(500, 100);
myWindow.focus(); ```

I want to close the firefox browser which is opened through backend C# process

I want to close the firefox browser which is opened through backend C# process. All other browsers support window.close(); opened through C# process. But firefox does not support. My code in C# Process.Start("firefox", "http://www.google.com"); After opening the browser i am calling this js code. window.close(); all other browsers working perfectly. but FF. if you can help me on this.
According to this documentation, script should not be able to close a window that it did not originally open:
The Window.close() method closes the current window, or the window on which it was called.
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
So, while it works in IE and Chrome today, don't count on it working forever.
If you want to close the window programmatically, it seems like your best option may be to close the process from your c# code, e.g.
var p = Process.Start("firefox", "http://www.google.com");
System.Threading.Thread.Sleep(10000); //Wait 10 seconds
p.CloseMainWindow();

In Firefox the window is not re-sizeing using JavaScript,

I have a JavaScript to re-size all my popup windows:
function resize()
{
window.resizeTo(240,230);
}
But now it is not resizing in Mozilla Firefox, but it was doing earlier, also
or if the popup window is opened in a new tab, it is not resizing, also in some browsers it is not also. Is there any piece of JavaScript code which works in all scenarios and all browsers?
Firefox comes with a preference for user to allow/disallow resizing of
window using Javascript. It's in Tools - Options - Content - Enable
Javascript -> [Advanced].
I am not sure if resizing is disabled by default, but you might want
to check your own Firefox installation first.
If it's disabled by default, then unfortunately there is nothing you
could do to resize the window after it has been opened. An ugly
workaround would be to open itself once again using window.open() with
the preferred size though.
Source: timdream (here)
I'll also add that:
You can't be assured that any browser will let you control the size of
windows you create. You can't even be sure you'll get a window at all
- people can instruct their browsers to open all new windows as browser tabs
Source: Pointy (same source as timdream)

Popup issue on iPad

I have observed an issue or what seems like a bug on iPad Safari.
Basically I have a link to open a popup using the normal window.open() Javascript method. Now this works fine most of the times on iPad Safari, but on a few instances, it opens the child page in the same window (rather than a separate child window)
It happens once in like 25 tries.
Please let me know if this is a known iPad issue OR if you have observed this inconsistent behavior with popups on your pages.
Thank you.

Opening modal dialog window is not working in Chrome

Response To:
Opening Popup Window is not working in firefox and google chrome
Hi,I have similar code in above question.My code works fine in IE.
this.parent.window.showModalDialog('Counter.aspx', '',
'dialogHeight:170px;dialogWidth:150px;status:no;scroll:no;edge:sunken;toolbar:0;center:on;help:off;unadorned:yes;');
What can i do about this code in order to open this window in Google Chrome browser ?
Thanks for any assistance
Myra
showModalDialog works in chrome(its not truly modal though). the problem could be that it is blocking them. Chrome's minimalistic design doesnt even tell you that some times. try adding an exception for you current website.
you can find it under -
Options->Under The Hood Tab-> Content Settings Button -> Popups Tab -> Exceptions button

Categories