Forum Moderators: open
function openpopup(htmlcode, url, width, height, scroll, resize) {
if (newwindow) newwindow.close();
properties = 'width=' +width+ ',height=' +height+ ',scrollbars=' +scroll+ ',resizable=' +resize;
var newwindow = window.open(url,'newwindow',properties);
if (newwindow) {
if (!newwindow.opener) newwindow.opener=self;
if (htmlcode!="") newwindow.document.write(htmlcode);
newwindow.focus();
} else {
alert("Process interrupted and may have been incomplete.\n\nPlease disable your popup blocker!");
}
}
This popup function identifies popup blockers, and if the window did not open, it'll display an alert.
It's also capable of writing HTML into the new popup window.
Is there any expert here that have a better solution? Or able to see any fault in this function such that some users are unable to call the function?
This line must be wrong. It tests for a true value of a global variable, newwindow.
Firstly, unless this variable has been previously declared, you'll get an error.
Secondly, the function sets a local variable, newwindow, not a global, so the test will always be false, even the if the global variable has been declared.
var newwindow = new Function; // is this right?
? Going off on a tangent there.
1. Declare the variable outside the function:
var newwindow; // now if(newwindow) won't cause an error
2. Inside the function itself, when you come to set the variable, don't use the keyword, var (else you will be setting a local variable, not assigning the object ref to the global).
As to the whole process working in its entirety...I have no idea!
if(newwindow) //will newwindow return true or false?
I guess my question should be, how to determine if a window which has been assigned a name is opened. Just so that I can close it.
(i wonder why i'm not receiving email notifications of this thread? I have madesure to tick it everytime I post)
var newwindow;
function openpopup(htmlcode, url, width, height, scroll, resize) {
if (newwindow) newwindow.close();
properties = 'width=' +width+ ',height=' +height+ ',scrollbars=' +scroll+ ',resizable=' +resize;
newwindow = window.open(url,'newwindow',properties);
//if (newwindow) {
if (!newwindow.opener) newwindow.opener=self;
if (htmlcode!="") newwindow.document.write(htmlcode);
newwindow.focus();
//} else {
//alert("Process interrupted and may have been incomplete.\n\nPlease disable your popup blocker!");
//}
}
I fixed an error handler to send me all error messages. I get mysterious error messages from different computer around the world.
Error message= Object is not connected to server
Error message= 'document' is null or not an object
Error message= Unspecified error.
Error message= The callee (server [not server application]) is not available
and disappeared; all connections are invalid. The call did not execute.
Among these lines, can't really tell which lines since different browser interpret line numbers differently.
if (!newwindow.opener) newwindow.opener=self;
if (htmlcode!="") newwindow.document.write(htmlcode);
newwindow.focus();