popup problem with FF

P

Paul J. Le Genial

Hello,

I have a problem with this script in Firefox :

var ipp =
window.open("","MadoPop","width=100,height=100,dependant=yes,resizable=no,ho
tkeys=no",true);
ipp.document.write('<html><body>test</body></html>');
ipp.document.close();
ipp.focus;

The popup windows that opens is resizable and has a visible statusbar. What
can I do to disable these two features ?


I know that people don't like popup windows ...unless they know what will
happens and choose to open it:
I want the ability to show enlarged pictures out of my text with a popup.
Events onclick and onblur in the popup will close it.
An advertisement will be displayed below each enlargeable picture to explain
that a popup will be created.

TIA
 
K

kaeli

I have a problem with this script in Firefox :

I'm surprised that's the only one.
You can't go misspelling param names and adding arguments. Trust IE to try to
figure it out for you instead of telling you that you did something wrong.

You do know that Firefox has a javascript console to show you errors, right?
Type
javascript:
in the URL address bar or do Tools->Javascript Console.
var ipp =
window.open("","MadoPop","width=100,height=100,dependant=yes,resizable=no,ho
tkeys=no",true);

window.open("","MadoPop","width=100,height=
100,dependent=yes,resizable=no,hotkeys=no,status=no");

And what's with the extra "true" param? The method window.open() only takes
3. Not 4.

Google is your friend.
http://www.devguru.com/Technologies/ecmascript/quickref/win_open.html

--
--
~kaeli~
Experience is something you don't get until just after you
need it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
P

Paul J. Le Genial

kaeli said:
I'm surprised that's the only one.
You can't go misspelling param names and adding arguments. Trust IE to try to
figure it out for you instead of telling you that you did something wrong.

You do know that Firefox has a javascript console to show you errors, right?
Type
javascript:
in the URL address bar or do Tools->Javascript Console.


dependent=yes,resizable=no,hotkeys=no,status=no");
OK, I wrote "dependant", but that was not the reason of the problem. I added
these params
to try to solve the problem, without success.

Here is the complete script:

function showPict(img,x,y) {
var text='<html><body onblur="this.close()" ';
text += 'onclick="this.close()" background="'; // onclick is not working in
FF
text += param;
text += '" onload="this.resizeTo('+ x + ',' + y + ')">test</body></html>'
var ipp =
window.open("","MadoPop","width=100,height=100,dependent=yes,resizable=no,ho
tkeys=no",true);
ipp.document.write(text);
ipp.document.close();
ipp.focus;
}


And in the body of the page, I have:
<a href="javascript:void()" onclick="showPict('image.jpg',680,540)"><img
src="small-image.jpg" width="200" height="152" border="0"></a>

The popup is resizable and has a status bar in FF (why ?), not in IE.

And what's with the extra "true" param? The method window.open() only takes
3. Not 4.
from this site :
http://javascriptkit.com/jsref/window.shtml

"open(URL, [name], [features], [replace])"

"Opens a new browser window. "Name" argument specifies a name that you can
use in the target attribute of your <a> tag. "Features" allows you to
show/hide various aspects of the window interface. "Replace" is a Boolean
argument that denotes whether the URL loaded into the new window should add
to the window's history list. A value of true causes URL to not be added."

This argument is not the reason of my errors.
 
P

Paul J. Le Genial

function showPict(img,x,y) {
var text='<html><body onblur="this.close()" ';
text += 'onclick="this.close()" background="'; // onclick is not working in
FF
Sorry, onclick works in FF but not in IE
 
R

RobB

Paul said:
working
Sorry, onclick works in FF but not in IE

window.open("","MadoPop","width=100,height=100,dependent=yes,resizable=no,ho
IE.

Firefox allows users to disable toggling of the status bar or
resize-ability by scripts. See the Options/Preferences Window for
details.

Might go:

text += 'onclick="top.close()"....
 
K

kaeli

function showPict(img,x,y) {
var text='<html><body onblur="this.close()" ';
text += 'onclick="this.close()" background="'; // onclick is not working in
IE

The "this" keyword may not be pointing to the object you assume it is. In
fact, I bet it refers to the document object in MSIE (and to window in FF).
Which won't close the window in IE.
Try self.close().
text += param;
text += '" onload="this.resizeTo('+ x + ',' + y + ')">test</body></html>'

Again, for cross-browser scripting, best to specifically call window.resizeTo
(or self.resizeTo). Don't use "this". It refers to document in some browsers
and window in others.
var ipp =
window.open("","MadoPop","width=100,height=100,dependent=yes,resizable=no,ho
tkeys=no",true);

You need to set status=no for some browsers. Try that. I always specifically
set them to no when I want to make sure they aren't there.
ipp.document.write(text);

I believe you have to open it first. If you don't have to, it's still better
form.
ipp.document.open();
ipp.document.write(text);
ipp.document.close();
And in the body of the page, I have:
<a href="javascript:void()"

Ooh, icky. Old skool. In a bad way.

<a href="someNonJsWarningPage.html"
onClick="showPict('image.jpg',680,540);return false;">

The popup is resizable and has a status bar in FF (why ?),

Keep in mind that FF allows me to tell my browser to not allow scripts to
disable those things. Check your FF preferences before you think your script
is actually broken. In MY FF, you can't open a new window at all. ;)
It will open in a new tab no matter what your script says. I set it up that
way because I hate when people spawn popups. That means when you resize, it
resizes EVERYTHING, so I have that turned off, too.
FF is all about customization.

I don't remember what the defaults are, so check what your scripts are set to
be allowed to do. Tools->options->web features
Click Advanced button. Make sure "move or resize windows" is checked and
"hide the status bar" is checked. Mine are both unchecked. ;)
And what's with the extra "true" param? The method window.open() only takes
3. Not 4.
from this site :
http://javascriptkit.com/jsref/window.shtml

"open(URL, [name], [features], [replace])"

That is not official documentation.
This is. Well, for Gecko anyway.
http://www.mozilla.org/docs/dom/domref/dom_window_ref76.html

The 4 args is, apparently, MSIE specific, since MSIE docs have it and Gecko
does not. This is not unusual. Different browsers support different things.
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.asp

Be careful what references you read and always check the browser
documentation to see what is supported.
This argument is not the reason of my errors.

Probably not (probably ignores that 4th one), but it might really fudge up
Safari, for all I know. :)

--
--
~kaeli~
Contrary to popular opinion, the plural of 'anecdote' is
not 'fact'.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
P

Paul J. Le Genial

Firefox allows users to disable toggling of the status bar or
resize-ability by scripts. See the Options/Preferences Window for
details.

OK, in javascript preferences I checked "allow disabling statusbar" and the
two problems
were solved: no statusbar and popup not resizable
Might go:

text += 'onclick="top.close()"....

OK, it works. self.close() is working too (thanks to kaeli)
 
P

Paul J. Le Genial

kaeli said:
The "this" keyword may not be pointing to the object you assume it is. In
fact, I bet it refers to the document object in MSIE (and to window in FF).
Which won't close the window in IE.
Try self.close().

OK, it is working now. I didn't thought of it because onblur was working
correctly. Of course, it was not applying to the same object.
Ooh, icky. Old skool. In a bad way.

<a href="someNonJsWarningPage.html"
onClick="showPict('image.jpg',680,540);return false;">

Is the "return false;" mandatory ? What is its role ? Can it be moved as the
last statement of the showPict function definition ?


Keep in mind that FF allows me to tell my browser to not allow scripts to
disable those things. Check your FF preferences before you think your script
is actually broken. In MY FF, you can't open a new window at all. ;)
It will open in a new tab no matter what your script says. I set it up that
way because I hate when people spawn popups. That means when you resize, it
resizes EVERYTHING, so I have that turned off, too.

So, would it be better to do it like this :
var ipp=eval(window.open("","MadoPop","width='+x+',height='+y+'")');
without the need to use resizeTo ?
I don't remember what the defaults are, so check what your scripts are set to
be allowed to do. Tools->options->web features
Click Advanced button. Make sure "move or resize windows" is checked and
"hide the status bar" is checked. Mine are both unchecked. ;)

OK, that's fine now.

Thank you for your clear explanations.
 
P

Paul J. Le Genial

I tried to replace the background="" parameter of the body tag by :
<head><style>BODY { background: black url('+img+')
no-repeat;}</style></head>
(I also tried : { background-image: url('+im+'); } )

Works in IE but in FF the style don't seems to be applied (no image
displayed)
 
R

Randy Webb

Paul said:
Is the "return false;" mandatory ?
No.

What is its role ?

It stops the navigation of the href attribute.
Can it be moved as the last statement of the showPict function definition ?

Only if you change the onclick to return showPict(....) and then return
false in the function.
So, would it be better to do it like this :
var ipp=eval(window.open("","MadoPop","width='+x+',height='+y+'")');
without the need to use resizeTo ?

No, it is *never* better to use eval.

http://jibbering.com/faq/#FAQ4_40
 
K

kaeli

I tried to replace the background="" parameter of the body tag by :
<head><style>BODY { background: black url('+img+')
no-repeat;}</style></head>
(I also tried : { background-image: url('+im+'); } )

Works in IE but in FF the style don't seems


Check the browser source and see what was actually written.


--
 
R

RobB

Paul J. Le Genial wrote:

(snip)
function showPict(img,x,y) {
var text='<html><body onblur="this.close()" ';
text += 'onclick="this.close()" background="';
text += img;
text += '" onload="this.resizeTo('+ x + ',' + y +
')">test</body></html>'

I tried to replace the background="" parameter of the body tag by :
<head><style>BODY { background: black url('+img+')
no-repeat;}</style></head>
(I also tried : { background-image: url('+im+'); } )

Works in IE but in FF the style don't seems to be applied (no image
displayed)

Are you passing a relative url? Since you're creating the new document
dynamically, it has no base url. Try a fully-qualified one if so.

Here's a tip: the best way (imo) to do this is to skip document.write
completely and use a javascript: url (favelet) to create the document.
Sample:

function getHTML(img, x, y)
{
return [
'<html><head></head>' ,
'<body onblur="top.close()" ' ,
'onclick="top.close()" ' ,
'style="background:black ' ,
'url(' + img + ') no-repeat;" ' ,
'onload="this.resizeTo(' + x + ',' ,
y + ')"><h3>test</h3></body></html>'
].join('');
}

var ipp = null;
function showPict(img, x, y)
{
if (ipp && !ipp.closed)
ipp.close();
var url = 'javascript:eek:pener.getHTML("'+img+'",'+x+','+y+')';
ipp = window.open(url, 'MadoPop',
'widt­h=100,height=100,resizable=no');
if (ipp && !ipp.closed)
ipp.focus();
return false;
}

<a href="image.jpg" target="ipp" onclick="return
showPict(this.href,680,540)"><img
src="small-image.jpg" width="200" height="152" border="0"></a>

Your non-JS users will still get a new window, with the pic. The false
return cancels the link when JS does run. There are no possible timing
errors ('access denied') when you write to a new window this way, as
the favelet is loaded just like an actual url.
 
K

kaeli

This is always the first thing to do but the result was correct, see below :
<html><head><title>Mado</title>
<style>BODY { background-repeat: no-repeat; background-image:
url(http://127.0.0.1/MADO/data/pict/D3358(681x540).jpg); }</style>
<script type="text/javascript">var opp=window.opener; </script></head>
<body>&nbsp;</body></html>

[theory]
The file name appears to have parens in it.
Don't you think the parser might get confused as to which parens closes the
url attribute?
Rename your file and see if it works.

It's always best (cross-platform) to not put spaces or characters like parens
or brackets in your file names. Keep them to starting with a letter and
having only letters, numbers, dashes, and underscores in them. You won't have
problems that way.
[/theory]

--
--
~kaeli~
If a chicken and a half can lay an egg and a half in a day
and a half, how long would it take for a monkey with a
wooden leg to kick the dill seeds out of a pickle?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
P

Paul J. Le Genial

kaeli said:
This is always the first thing to do but the result was correct, see below :
<html><head><title>Mado</title>
<style>BODY { background-repeat: no-repeat; background-image:
url(http://127.0.0.1/MADO/data/pict/D3358(681x540).jpg); }</style>
<script type="text/javascript">var opp=window.opener; </script></head>
<body>&nbsp;</body></html>

[theory]
The file name appears to have parens in it.
Don't you think the parser might get confused as to which parens closes the
url attribute?
Rename your file and see if it works.

It's always best (cross-platform) to not put spaces or characters like parens
or brackets in your file names. Keep them to starting with a letter and
having only letters, numbers, dashes, and underscores in them. You won't have
problems that way.
[/theory]

That was it ! I removed the parenthesis and now it's working. Thank you
again for your valuable help.
 
P

Paul J. Le Genial

Paul J. Le Genial wrote:

(snip)

Kaeli found the origin of the problem, still your idea is interesting. I'll
think of it. Thank's again for your help and ideas.
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top