Forum Moderators: open

Message Too Old, No Replies

Check if Pop ups are allowed

         

andrewsmd

4:01 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a script that I found on the internet that checks if pop ups are allowed. The only problem is, it pops up a small little window for a second every time the page loads. I'm wondering if there is a way to either not have the user see the pop up box or at least only try it once a session. I tried setting the position to -100 to get it off of the screen but that didn't work. Here is my code.

//test to see if their pop up blocker is on
var mine = window.open('','','width=1,height1,left=-10,top=-10,scrollbars=no');
if (mine) {
var popUpsBlocked = false
mine.close()
} //if mine
else {
var popUpsBlocked = true
}//else


if(popUpsBlocked){
alert("You are blocking pop ups from this site.\n"+
"In order to use the print function, you must allow popups.\n" +
"Please browse to SNIP"+
" if you are unsure how to do this.");
}//if popUpsBlocked

Thanks,

[edited by: Fotiman at 4:18 pm (utc) on Dec. 4, 2009]
[edit reason] No URLs please. See TOS [webmasterworld.com] [/edit]

rocknbil

8:22 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it pops up a small little window for a second every time the page loads.

Look for code containing "setTimeout()", this is what will recursively call the function.

andrewsmd

8:26 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not following how the setTimeout function would help me in this case. Can you explain a little more please. Thanks and excuse my stupidity.

Fotiman

9:53 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First, I would suggest that it's probably not a good requirement that users enable popups in order to print... so however it is that you're handling print is probably not a good way of doing things.

That said, though, if this popup check is only needed to determine if the user can print, then why not simply move that code to only execute when the user tries to print? That is, instead of executing every time the page loads, only execute it when the user tries to print (I'm assuming you have some button or link that the user clicks on, so attach that code to the event handler for that button).

andrewsmd

9:58 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is a good idea. I agree with you on the print option, but the client "wants a button that brings up my printer screen for me to print". How else do I accomplish that without creating a new page with printer friendly html?

rocknbil

1:50 am on Dec 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not following how the setTimeout function would help me in this case.

The setTimeout is what's causing it to pop up once a second. If you want to just check it once, on site entry, you'll need to locate this and disable it.

How else do I accomplish that without creating a new page with printer friendly html?

in your php,

echo (isset($_GET['print-me']))?'print stylesheet':'regular stylsheet';

Or if it's static HTML, or really simple (only a few items to hide,) use @media print selectors, setting non printing items to display:none.

@media print {
form input { display:none; }
}

Fotiman

5:12 am on Dec 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@rocknbil, I think you misread the original post. It did not say it was popping up once a second, it said:

it pops up a small little window for a second every time the page loads

setTimeout is not relative in this particular case.

rocknbil

7:43 pm on Dec 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<facepalm>