Why does this not work as a function and only in the head of document

P

paul

HI! I have being to add the following as part of a function but it just will
not work as is but I don't know why, can someone point out why.

This opens up a popup window for a popup detection and is works in the head
of a page..

<script type="text/JavaScript" language="JavaScript">
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()
</script>

This part displays an alert to the user if the window fails to open, this
part can be placed in the body and also works in a function.

<script type="text/JavaScript" language="JavaScript">
if(popUpsBlocked)
alert("We have detected that you are using popup blocking
software.\nPlease Disable it for this site or some features may not work
correctly.\n\nNOTE: If you are using Norton Internet Security you might have
to disable spam blocking\nor our menu system may or may not work
correctly.");
</script>

I can put it as part of a function like this.

function checkblockandpop(){
if(popUpsBlocked)
alert("We have detected that you are using popup blocking
software.\nPlease Disable it for this site or some features may not work
correctly.\n\nNOTE: If you are using Norton Internet Security you might have
to disable spam blocking\nor our menu system may or may not work
correctly.");
}

and call it with
<script type="text/javascript">
checkblockandpop();
</script>

But I want to put both together so I can use it as part of a detect function
and then set a cookie so that it displays only once to the user so it does
not annoy the user. but I don't know how to make them together.

Paul
 
R

RobG

paul said on 28/04/2006 2:33 PM AEST:
HI! I have being to add the following as part of a function but it just will
not work as is but I don't know why, can someone point out why.

This opens up a popup window for a popup detection and is works in the head
of a page..

It's actually a futile exercise, you can't reliably detect popup
blockers so don't make your site dependent on them.

Following comments are for the record...
<script type="text/JavaScript" language="JavaScript">

The language attribute is deprecated, remove it. Keep type.

var mine =
window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
if(mine)
var popUpsBlocked = false
else
var popUpsBlocked = true

You can set the value of 'popUpsBlocked' directly, no need for if..else:

var popUpsBlocked = !mine;

mine.close()

If the popup was blocked so that the call to window.open didn't return
an object, 'mine' probably doesn't exist. This will cause an error and
your script will stop. Since it's at the end of this script anyway and
it doesn't return any value, subsequent scripts should still run.

If this is inside a function then the error will likely halt any further
script. You need to test whether mine was created and act accordingly.


function testPop()
{
var testPop = window.open('','testPop','');
var blocked = (testPop)? 'not blocked' : 'blocked';
if (testPop && !testPop.closed) testPop.close();
alert('Popup ' + blocked);
}
testPop();

[...]
But I want to put both together so I can use it as part of a detect function
and then set a cookie so that it displays only once to the user so it does
not annoy the user. but I don't know how to make them together.

It won't work reliably anyway, so forget it.
 
P

paul

RobG said:
paul said on 28/04/2006 2:33 PM AEST:
HI! I have being to add the following as part of a function but it just
will not work as is but I don't know why, can someone point out why.

This opens up a popup window for a popup detection and is works in the
head of a page..

It's actually a futile exercise, you can't reliably detect popup
blockers so don't make your site dependent on them.

Following comments are for the record...
<script type="text/JavaScript" language="JavaScript">

The language attribute is deprecated, remove it. Keep type.

var mine =
window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
if(mine)
var popUpsBlocked = false
else
var popUpsBlocked = true

You can set the value of 'popUpsBlocked' directly, no need for if..else:

var popUpsBlocked = !mine;

mine.close()

If the popup was blocked so that the call to window.open didn't return
an object, 'mine' probably doesn't exist. This will cause an error and
your script will stop. Since it's at the end of this script anyway and
it doesn't return any value, subsequent scripts should still run.

If this is inside a function then the error will likely halt any further
script. You need to test whether mine was created and act accordingly.


function testPop()
{
var testPop = window.open('','testPop','');
var blocked = (testPop)? 'not blocked' : 'blocked';
if (testPop && !testPop.closed) testPop.close();
alert('Popup ' + blocked);
}
testPop();

[...]
But I want to put both together so I can use it as part of a detect
function and then set a cookie so that it displays only once to the user
so it does not annoy the user. but I don't know how to make them
together.

It won't work reliably anyway, so forget it.

HI! And thanks for responding. and thanks for pointing out the problems, I
am still a novices at js but I am learning. I noticed that when I enabled
the blocker that it did give me an error with "mine", but I thought its a
syntax error and not logic error.

Yes a agree that it is not reliable, but I use a floating js menu and in
very rare cercumstances (1% 3%) depending on the type popup blocker and
browser it will cause the menu not to show up. I do have alternate menu as a
backup for the user if the first fails but the first menu is far better and
if I can save that 1 to 3 percent I would like to offer the user a way to
corrected it and tell him that there is solution.

I also have it listed in a FAQ.

That's why when it comes to fancy floating menu systems nothing beats a pure
Flash site for reliabilaty and compatibilaty. I think the best of both
worlds is combining Flash with scripting languages like in the case of
compiling a swf file with northcode swf studio v3 so it can intergrate with
js as naturally as it calls ActionScript API functions. together they form a
powerfull team and is why I am learning JS.

Thanks again :)

Paul
 
R

RobG

paul wrote:
[...]
Yes a agree that it is not reliable, but I use a floating js menu ...
when it comes to fancy floating menu systems nothing beats a pure
Flash site for reliabilaty and compatibilaty.

You can guess my feelings about that - I run Firefox with popup
blocking and Flashblock enabled (and use a spell checker to boot :) ).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top