We are a bit in trouble.
We show some informations for specific sites in our own firefox extension (for several reasons we use a xul box-Element for that presentation).
We don't wan't the box to show in browser popups.
But: How do we identify a browser-window as a popup in our extension code (javascript)?
Thanks a lot!
You may check:
if the window does have an opener => if(window.opener)
to determine if it was opend using javascript
if the window does have an opener, check if it is the top-window =>if(self==top)
to determine that the window is not a frame
When both conditions are true, you may assume that the window is a popup.
Related
I work in a situation where the computer I use is inconsistent, and I often have never logged onto the computer I'm working on before. As such, I use chrome and launch most of the things I need using the "on startup" option.
My issue is that I have a page that I would like to open in a separate window. I've done some finagling with a javascript bookmarklet that does something similar to what I want, but it isn't perfect.
javascript:window.open("http://google.com","_blank","foobar"); javascript:window.close();
This will open a new window at google.com as expected, however It has a few flaws:
The window is not fullscreen. It will always open at a smaller window size, and is horribly inconsistent on where it will show up.
It isn't a standard window, I can't type in the address bar, add tabs, see my bookmarks bar, or use javascript.
I honestly don't know what the second and third parameters in window.open do, the window will open in a tab instead of a window if I don't have them, but it doesn't care what is there.
I have attempted passing javascript commands through the window.open command, but the window refuses to do any of them.
I understand that this is the type of thing that shouldn't be decided by a webpage, and should be left to a user. But I am the user...
I believe that most of the parameters you mentioned (fullscreen window, window size, other window features) are specified in the third argument of window.open(). For example:
window.open("http://google.com","_blank","fullscreen=yes;menubar=yes;titlebar=yes")
would open http://google.com in a new window (_blank) in fullscreen view (fullscreen=yes;) and render the menubar and titlebar (menubar=yes;titlebar=yes). A list of standard values is provided at w3schools.com and developer.mozilla.org
Is there a good way to determine if a person has a popup blocker enabled? I need to maintain a web application that unfortunately has tons of popups throughout it and I need to check if the user has popup blockers enabled.
The only way I've found to do this is to open a window from javascript, check to see if it's open to determine if a blocker is enabled and then close it right away.
This is slightly annoying since users who do not have it enabled see a small flash on the screen as the window opens and closes right away.
Are there any other non-obtrusive methods for accomplishing this?
Read Detect a popup blocker using Javascript:
Basically you check if the 'window.open' method returns a handle to a newly-opened window.
Looks like this:
var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
if(mine)
var popUpsBlocked = false
else
var popUpsBlocked = true
mine.close()
As others have said, you'll have to try it and see, but checking for the resulting window object being non-"falsy" isn't sufficient for all browsers.
Opera still returns a Window object when a popup is blocked, so you have to examine the object sufficiently to determine if it's a real window:
var popup = window.open(/* ... */);
var popupBlocked = (!popup || typeof popup.document.getElementById == "undefined");
As others have commented, the only way to find out for sure is to try it.
However, a good approximate answer to the question “is a popup-blocker installed” is, these days, “yes”. All recent browsers will block your pop-ups by default, so you'd better design your app to cope gracefully with this. Namely, don't try to window.open except in reaction to a user interaction (typically onclick), and you'll be fine.
I don't think there is any way of detecting this without attempting to open a window, as popup blockers don't add anything that can be interrogated in JS.
Popups that are opened in response to an action by a user—such as clicking a link—shouldn't be blocked by popup blockers.
The reading of this Avoid browser popup blockers confirm my feelings that add blocker does simply allow popup that are opened by a user generated event.
I'm using dhtmlxgrid and get notified from a user click over one cell through the "onRowSelect" event but calling raise a problem with Firefox and Chrome ad blocker :
window.open(url, "_blank");
Any idea or magic solutions.
Are you using the Dhtmlx Window component? because that call window.open() is pure JS call.
You may try to create a DhtmlxWindow object that is a DIV and it should not be blocked, I used this before and never got problems.
Here's a simple INIT guide to use dhtmlx Window.
http://dhtmlx.com/docs/products/dhtmlxWindows/samples/01_init/01_minimal_init.html
It seems like when trying to open 2 windows from a succession of windows.open calls, it only allows the first window to open and deletes the reference to the second window. I know this probably sounds a little kludgy, but we do need to have that second popup.
Any ideas?
Unfortunately we are addressing a user-case, where ie6 on the user end has popup blocker enabled.
EDIT: I just realized that you probably are using a blank ('') window name for both windows:
var win = window.open(url, '', 'blah=1');
var win2 = window.open(url2, '', 'stuff=1'); //later
This is probably handled with different windows in browsers other than IE6.
If that does not work, you might consider injecting divs that display on top of your content (instead of using popups), which is considered a better practice.
The IE pop-up blocker, by default, only allows one new window to be opened per user-initiated-action (i.e. a click on some element). If you try to open two new windows in the same handler in response to a single user-initiated-action, only the first window will successfully be opened. This is by design.
There is an override key that users can use: on IE6 I think it is CTRL, but it might be CTRL+ALT because it got changed in later versions (not sure if that was back-ported or not).
If you go to Tools->Internet Options->Pop-up Blocker->Settings->Blocking Level: and look at the value in the drop-down box for "High" it will tell you the override key in a parenthetical phrase.
In the same settings dialog, you can also add this specific site to the "Allowed sites" list, and then pop-up blocker will let all new window creation attempts on said site succeed. I'm pretty sure this list can also be pre-populated through group policy or IEAK or something like that too. But it's just a list that is stored in the registry, so you can also write log-in scripts that will just add things if they need to be added.
If you have further questions, let me know (I was the developer who implemented the IE pop-up blocker).
IE6 makes it sound like it's a corporate installation. Assuming that's true, contact your administrators and have group policy set your internal website to be in the Intranet zone, and turn off the popup blocker for that zone.
In IE7, a child window opened with window.open can close itself using window.close(), but a window opened with <a href=... target=_blank> will show a security warning if the child window tries to close itself.
In my application, I don't know how my child window is opened, and I need to know (in the child window JavaScript code) whether I can use the window.close() or not. Is there a way? Another way to ask the question is - is there a way in IE to differentiate between a window opened via window.open vs a window opened via target=_blank.
I tried checking window.opener but in both cases, there is a value there, so this does not allow me to differentiate between the two cases.
Try comparing window.opener and window.self
Source: Close window without the prompt message in IE7
This is how to avoid the prompt according to the page above:
function WinClose(){
window.open('','_self','');
window.close();
}
Close
Is this a possible approach for your page?
Just a blind shot, but you can try removing the onunload event in the window, in case it is there.
If you have control over the window.open events, you could give the new window a name (2nd parameter I think). You can then check for that name before applying window.close().