This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes sometimes window not opened Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "sometimes window not opened" Watch "sometimes window not opened" New topic
Author

sometimes window not opened

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255


According to what I have heard from some people, sometimes when the user of my page clicks on the button to open the new window, it does not open. I know that the command to open the new window was supposed to be followed by the browser because when the user notices that the new window does not open, the user clicks again and gets the message that the window was already opened. This happens sometimes, not all the time.
What could the reason be for a browser not to follow a command to open a new window? Maybe the security level is too high, or maybe it does not open a new window when too many windows are opened.
I thought about changing to this command:


Would this work 100% of the time?
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
The reason is that you just check a boolan variable that has no reference to the popup.
Try to write the opened window to a variable and the check for it's document object.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Using a boolean is bad because it doe not know what the state of the window is. A user could have closed it.



Eric
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
A couple questions:
What is newWindow in Chris Baron's example? Is that a boolean or an object? Why are both booleans needed in this?

Is "newWindow" in the above code a check whether or not the object is null or not, to prevent an error which could occur by checking newWindow.document?
Is "windowName" in Eric's example the same kind of thing?

Thank you for the code advice, but also what I really want to know is, why do some people's browsers not open a window like they are told to? And what kind of advice can I give to people so that they can increase the chance that their browser will open the new window?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Pop Up blockers block windows. If the user did not perform an action that could open the window, it is almost guaranteed that the browser will block it.



In this day in age, most people avoid pop up windows like the plague and use modal layers on top of the content.

Eric
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
What does "use modal layers on top of the content" mean?

Also, I tried this:



But I got an error. Is mywindow in this example a window object or a boolean, or what?
How can I refer to a window which the program opens?
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Kevin Tysen wrote:A couple questions:
What is newWindow in Chris Baron's example? Is that a boolean or an object? Why are both booleans needed in this?

It's null or an window object
Kevin Tysen wrote:

Is "newWindow" in the above code a check whether or not the object is null or not, to prevent an error which could occur by checking newWindow.document?
Is "windowName" in Eric's example the same kind of thing?

Yes
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Kevin Tysen wrote:What does "use modal layers on top of the content" mean?

It's html that looks like a popup. It made e.g. with a div. To get it above the other content its css value for z-index is set up and it's positioned absolute.
Kevin Tysen wrote:Also, I tried this:

But I got an error

Eric posted the answer already:
Eric Pascarello wrote:If the user did not perform an action that could open the window, it is almost guaranteed that the browser will block it.
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255

var mywindow = window.open("apage.html");
var mydocument = mywindow.document;

When I tried this I got an error, but I don't think the error occurred because the browser blocked the popup window. I found an example similar to this on w3schools home page and it worked fine. In this example too, there was no error when I had only the window.open command, but the error occurred after I added the second line. What I think is that there is an access error. The above open statement actually looks more like this:

apage.html is not my page, but someone else's. Is there some rule that you can't get access to the document object of a window displaying someone else's page?
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
No, cross domain access is not possible. Better use !newWindow.closed, like Eric posted.
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Thank you.
 
GeeCON Prague 2014
 
subject: sometimes window not opened