473,788 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript">
var mine =
window.open('', '','width=1,hei ght=1,left=0,to p=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="JavaS cript">
if(popUpsBlocke d)
alert("We have detected that you are using popup blocking
software.\nPlea se Disable it for this site or some features may not work
correctly.\n\nN OTE: 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 checkblockandpo p(){
if(popUpsBlocke d)
alert("We have detected that you are using popup blocking
software.\nPlea se Disable it for this site or some features may not work
correctly.\n\nN OTE: 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">
checkblockandpo p();
</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 1502
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="JavaS cript">
The language attribute is deprecated, remove it. Keep type.

var mine =
window.open('', '','width=1,hei ght=1,left=0,to p=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.
--
Rob
Group FAQ: <URL:http://www.jibbering.c om/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="JavaS cript">


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

var mine =
window.open('', '','width=1,hei ght=1,left=0,to p=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
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
2978
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 position back against the book for syntax errors but still cannot get this script to work. I tells me that; 1. Line 49 has a missing ";" at bye 13 2. Line 89 has a missing object at byte 1
3
8437
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 this in the HEAD of my document - the page will wait until it downloads. If I place it in the BODY of my document - supposedly the page
11
2030
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 should be reproducible with that version at least. BACKGROUND: =========== When you open this page in your browser, you will see a 4 cell table. The cells contain the following items respectively:
4
11956
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 code for the first line (click the Table HTML button:)) you will fine that the code displayed is not the same as was written. "onChange" was changed to "onchange" etc. Please help. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">...
4
3607
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 just hangs and keeps loading forever. I checked around on the web and in USENET, but I haven't seen any mention of split() not working in Mozilla. Thoughts? Thanks in advance. <HTML> <HEAD> </HEAD>
10
1570
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
1665
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. Can anyone point out which one it is and how to make it both netscape and MS browser compatible? I hope if I can make the script compatible for those two at extreme, it will probably work with most browser out there. As you would notice, this form...
2
1486
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 += "document.writeln('<html><frameset rows=\"*,33%\">');\n"; s += "document.writeln('<frame src=\"' + document.location +
15
2156
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 to get all the obvious bugs out... Um... The script is at: http://ali.freezope.org/idf test and what it is supposed to show is at: http://ali.freezope.org/idf result
2
1487
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. An image caption (whose value is populated by my alt_img database field), also changes according to the current moused-over thumbnail image. All functions fine...except...for the initial value for the alt_jmg database field. The caption text for...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.