• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sometimes window not opened

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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?
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, cross domain access is not possible. Better use !newWindow.closed, like Eric posted.
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic