View Full Version : Why doesn't this Javascript code work in Opera browser?
Can anyone tell me why this code doesn't work in the Opera browser? It's supposed to open a tiny pop-up window when the browser is closed.
URL: http://tufat.com/popup.html
Here's all the code from the html file:
<body onUnload="logoff();">
When you close this window, CNN will open in a very tiny window.
<SCRIPT LANGUAGE="Javascript">
function logoff() {
window.open( 'http://www.cnn.com', 'POPUP', 'toolbar=no,scrollbars=no,width=1,height=1' );
}
</SCRIPT>
</body>
it's easy to turn popup's off in Opera. Also, it has a slightly different way of handling windows generally. In the end, it depends on how the user has configured the browser. You can't guarantee a popup.
Having said that, you might try using real window width and height.
hi,
I've changed it so that width=400 and height=400, and ensured that the "Allow Pop-ups" option is set in the Opera Preferences. But it still doesn't work. It does work in IE 4,5,6 and Netscape 4.x,6.
Thoughts?
- Darren
It can't test it because I don't have Oprea on this machine yet, but try something like this...
<script language="javascript">
<!--
var pSmall
function logoff(){
pSmall=window.open( 'http://www.cnn.com', 'POPUP', 'width=100,height=100' );
}
//-->
</script>
nope, that doesn't work either. The problem seems to be that the logoff() function is not being called at all, so I wonder if the onUnload property in the <body> tag is not supported in Opera or something. I'm using version 6.03 on Windows XP.
Is there some other way that the function can be called when a user closes the page?
chrismiceli
09-17-2002, 11:19 PM
does the <a href="http://www.whatever.com" target="mainframe">hi</a>
that should do a popup in html unless the link is on a frame, but if not it should work, this is a good way to see if popus work.
I've added the <a href...>hi</a> to the html file (see www.tufat.com/popup.html).
The "hi" popup seems to work fine... i.e., popups are enabled on the Opera browser that I'm using.
michael.hd
09-20-2003, 10:06 PM
I know that hate is self destructive - but this opera thing is really getting me there. I cant remember being so annoyed by any software that didn't have bill gates name on it!
Apparently only about 5% of people (max) use it. I think they are all programmers trying to ensure cross browser support...
Anyway I have a solution to the problem (sort of). I tried everything to get my popup to work on that damn opera but no joy at all. In desperation i tried putting the code directly into the page.
I.E. I stopped using the usual link to a javascript page. Without any other modifications at all. Suddenly it was working fine.
This is my code.......
<script type="text/javascript">
<!--
var popuphelp;
function pophelp2(chosenaddress)
{
if( popuphelp != null )
{
popuphelp.close();
}
window.open(chosenaddress, "", "top=120, left=200,width=200, height=200, scrollbars").focus();
}
-->
</script>
...this works in opera, BUT this....
<script type="text/javascript" src="../site/scripts/popup.js" language="JavaScript"></script>
...in the HEAD tag does not. Even though the code inside is identical.
Can anyone shed light on why???
Also can anyone direct me towards some opera helpsite which helps newcomers cope with its differences from the evil IE??
liorean
09-20-2003, 10:13 PM
Did you have the script tags or the html comment in the .js file? Those aren't allowed in .js files, they have to be pure JavaScript.
michael.hd
09-20-2003, 10:21 PM
No..
My actual ref in the head looks like this.......
<script language="JavaScript" src="../site/scripts/global.js" type="text/javascript"></script>
...and the page is formatted like this.......
<!--
code
-->
any other ideas. Do you know of any web pages where the javascript is stored in seperate files and still works in opera.?
glenngv
09-21-2003, 10:28 AM
remove the comment tags <!-- -->
liorean
09-21-2003, 10:36 AM
As I said (an glenngv clarified) you aren't allowed to have html comments in -js files. If you remove those, everything should work fine.
michael.hd
09-21-2003, 01:18 PM
Thank you both!
I was not seeing the woods for the trees. I thought of the <-- --> as javascript comments not html.
Anyway it all works now.
Could g8z please confirm if this has also fixed their problem. I think it may be quite a common error.
If it hasn't let me know as mine works fine in opera now, I will take another look at your code.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.