473,385 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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,s crollbars=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
Apr 28 '06 #1
3 1479
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,s crollbars=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.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 28 '06 #2
RobG wrote:
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,s crollbars=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
Apr 28 '06 #3
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 :-) ).
--
Rob
Apr 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news frontiernet.net | last post by:
I have key entered and tried to run example 4-6 from Dany Goodmans DYNAMIC HTML book, version one that is on pages 94-96. This is part of my effort to learn JavaScript. I checked each byte and...
3
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place...
11
by: Saqib Ali | last post by:
Please excuse me, this is a fairly involved question that will likely require you to save the file below to a file and open it in a browser. I use Mozilla 1.5, so the problem I describe below...
4
by: rick | last post by:
The following basic script works fine in firefox by not in IE. Can anyone spot the problem? In IE I can only delete the first line but not the lines created by javascript. Also, look at the HTML...
4
by: Brian Glen Palicia | last post by:
My goal is to accept input from the user into a text box and then parse the data using split(). The first step is this tiny program to test the split() function. It runs in IE, but in Mozilla it...
10
by: Brett | last post by:
This code is supposed to work in Netscape 4+ and IE 4+. It works fine in IE but in Netscape 7.2, I get a blank page. Any suggestions? Thanks, Brett <html> <head>
5
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible....
2
by: Vincent van Beveren | last post by:
I have the following (seemingly) useless piece of JavaScript <html> <head> <script type="text/javascript"> function frameMe() { s = "document.open();"; s +=...
15
by: greenflame | last post by:
First of all I only have IE for testing. Ok. I have a script that is supposed to show, not evaluate, the indefinite integral of something. When I run the script it just craches IE. I have tried...
2
by: haft | last post by:
My webpage of discussion contains a javascript powered image gallery of small thumbnail images that when moused-over, display a larger image that corresponds to the current moused-over thumbnail....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.