popup problem with FF

Discussion in 'Javascript' started by Paul J. Le Genial, Mar 16, 2005.

  1. 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
     
    Paul J. Le Genial, Mar 16, 2005
    #1
    1. Advertising

  2. Paul J. Le Genial

    kaeli Guest

    In article <4238733a$0$44091$>,
    enlightened us with...

    >
    > 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
     
    kaeli, Mar 16, 2005
    #2
    1. Advertising

  3. "kaeli" <> wrote in message
    news:...
    > In article <4238733a$0$44091$>,
    > enlightened us with...
    >
    > >
    > > 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);

    >
    > 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.
     
    Paul J. Le Genial, Mar 16, 2005
    #3
  4. > 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

    > 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.
     
    Paul J. Le Genial, Mar 16, 2005
    #4
  5. Paul J. Le Genial

    RobB Guest

    Paul J. Le Genial wrote:
    > > 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
    >
    > > 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.

    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()"....
     
    RobB, Mar 16, 2005
    #5
  6. Paul J. Le Genial

    kaeli Guest

    In article <423892d0$0$44077$>,
    enlightened us with...
    >>

    > 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
     
    kaeli, Mar 16, 2005
    #6
  7. >
    > 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)
     
    Paul J. Le Genial, Mar 16, 2005
    #7
  8. "kaeli" <> wrote in message
    news:...
    > In article <423892d0$0$44077$>,
    > enlightened us with...
    > >>

    > > 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().


    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.

    > >
    > >
    > > 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;">


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



    > > 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.


    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.
     
    Paul J. Le Genial, Mar 16, 2005
    #8
  9. "kaeli" <> wrote in message
    news:...
    > In article <423892d0$0$44077$>,
    > enlightened us with...
    > >>

    > > 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)
     
    Paul J. Le Genial, Mar 16, 2005
    #9
  10. Paul J. Le Genial

    Randy Webb Guest

    Paul J. Le Genial wrote:

    > "kaeli" <> wrote in message
    > news:...
    >
    >>In article <423892d0$0$44077$>,
    >> enlightened us with...


    <--snip-->

    >>>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;">

    >
    >
    > 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.

    >>>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.

    >
    >
    > 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

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Mar 17, 2005
    #10
  11. Paul J. Le Genial

    kaeli Guest

    In article <4238b9f1$0$44062$>,
    enlightened us with...
    >
    > 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.


    --
    --
    ~kaeli~
    If a parsley farmer is sued, can they garnish his wages?
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Mar 17, 2005
    #11
  12. "kaeli" <> wrote in message
    news:...
    > In article <4238b9f1$0$44062$>,
    > enlightened us with...
    > >
    > > 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.
    >

    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>
     
    Paul J. Le Genial, Mar 17, 2005
    #12
  13. Paul J. Le Genial

    RobB Guest

    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.
     
    RobB, Mar 17, 2005
    #13
  14. Paul J. Le Genial

    kaeli Guest

    In article <4239b85c$0$44086$>,
    enlightened us with...
    >
    > >

    > 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
     
    kaeli, Mar 17, 2005
    #14
  15. "kaeli" <> wrote in message
    news:...
    > In article <4239b85c$0$44086$>,
    > enlightened us with...
    > >
    > > >

    > > 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.
     
    Paul J. Le Genial, Mar 17, 2005
    #15
  16. "RobB" <> wrote in message
    news:...
    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.
     
    Paul J. Le Genial, Mar 17, 2005
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9obiBXYWxrZXI=?=

    Popup Window Popup Timing

    =?Utf-8?B?Sm9obiBXYWxrZXI=?=, Nov 4, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    865
    =?Utf-8?B?Sm9obiBXYWxrZXI=?=
    Nov 4, 2005
  2. dapkniht
    Replies:
    1
    Views:
    1,356
    Eliyahu Goldin
    Mar 8, 2006
  3. Rajesh
    Replies:
    0
    Views:
    583
    Rajesh
    Jul 31, 2007
  4. Urs Gubler
    Replies:
    0
    Views:
    159
    Urs Gubler
    Jul 2, 2003
  5. Jens Peter Hansen
    Replies:
    7
    Views:
    560
    Randy Webb
    Jun 19, 2004
Loading...

Share This Page