Web-page that *BOTH* changes current page + displays a Pop-up pagefrom JavaScript

Discussion in 'Javascript' started by John L., May 15, 2009.

  1. John L.

    John L. Guest

    I'm having trouble accomplishing the subject task in an HTML
    JavaScript.

    When I initially spec'd the function, I envisioned JavaScript source
    with the following flow:

    1) Create pop-up window via popupWindow = window.open(...)
    2) Change current page via window.location.replace(URL)
    3) Change focus to put pop-up window back on top via popupWindow.focus
    ()

    I did not anticipate that my JavaScript would terminate upon the
    completion of the method in #2 above. As a result, I have created a
    pop-down window, hidden behind the new page.

    Is there a methodology I can use to accomplish the desired task?

    Thanks in advance for your time and consideration.


    John L.
     
    John L., May 15, 2009
    #1
    1. Advertising

  2. Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    John L. wrote:
    > I'm having trouble accomplishing the subject task in an HTML
    > JavaScript.
    >
    > When I initially spec'd the function, I envisioned JavaScript source
    > with the following flow:
    >
    > 1) Create pop-up window via popupWindow = window.open(...)
    > 2) Change current page via window.location.replace(URL)
    > 3) Change focus to put pop-up window back on top via popupWindow.focus
    > ()
    >
    > I did not anticipate that my JavaScript would terminate upon the
    > completion of the method in #2 above.


    Of course it terminates -- where is the code to work on?

    > As a result, I have created a pop-down window, hidden behind the new page.


    Doesn't work.

    > Is there a methodology I can use to accomplish the desired task?


    Yes. Let code in a.html open b.html in a "pop-up window" (could be anything
    from the same window to a browser tab).

    Then, in a.html:

    <script type="text/javascript">
    /* (1) */
    var w;

    function popup(sURL, sWindowName)
    {
    if (w && !w.closed && isMethod(w, "focus"))
    {
    w.focus();
    }
    else if (typeof window != "undefined" && isMethod(window, "open"))
    {
    w = window.open("b.html", sWindowName, "resizable,scrollbars");
    }

    return !w;
    }
    </script>

    <a href="foo" onclick="return popup(this.href, 'bar')">...</a>

    In b.html:

    <head>
    ...
    <script type="text/javascript">
    function body_load(sURL)
    {
    if (typeof window == "undefined") return;

    /* (2) */
    var o = window.opener;
    if (o && !o.closed && o.location && isMethod(o.location, "replace"))
    {
    o.location.replace(sURL);
    }

    /* (3) */
    if (isMethod(window, "focus")) window.focus();
    }
    </script>
    </head>

    <body onload="body_load('foo')">
    ...
    </body>

    - The order of (2) and (3) may be reversed
    - Doesn't work with different URI schemes, host names, or ports (man SOP).
    - isMethod() is not a built-in; search for it.

    <http://jibbering.com/faq/#posting>


    HTH

    PointedEars
     
    Thomas 'PointedEars' Lahn, May 15, 2009
    #2
    1. Advertising

  3. Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    On May 15, 11:21 am, Thomas 'PointedEars' Lahn <>
    wrote:

    > Yes. Let code in a.html open b.html in a "pop-up window" (could be anything
    > from the same window to a browser tab).


    I have a question that I've wanted to ask for a long time. Is there
    any hack trick to ensure that IE7/8 will open a real new window rather
    than a new tab *regardless* of the user's preference settings?

    I have found a trick in Firefox. It is just a matter of choosing the
    right window properties in the third argument to window.open. Some
    combinations seem to force a new window to open, and others will open
    a tab if that is the user's browser setting.

    I think Chrome is like Firefox: some combinations of window properties
    will force a real window to open. I cannot even find a preference
    setting in Chrome to switch from "open popups in tabs" to "open popups
    in window."

    Safari always seems to open a new window when there is a call to
    window.open.

    If anyone has found any trick, especially for IE, I'd be interested to
    know about it even if it is a hack.

    Peter
     
    Peter Michaux, May 16, 2009
    #3
  4. John L.

    rf Guest

    Re: Web-page that *BOTH* changes current page + displays a Pop-up page from JavaScript

    Peter Michaux wrote:

    > I have a question that I've wanted to ask for a long time. Is there
    > any hack trick to ensure that IE7/8 will open a real new window rather
    > than a new tab *regardless* of the user's preference settings?


    Hey, this is *my* browser mate. I'll open stuff in a new window if *I* see
    fit.

    It's bad enough you are opening a new tab.
     
    rf, May 16, 2009
    #4
  5. John L.

    Timo Reitz Guest

    Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    Peter Michaux wrote:
    > I have found a trick in Firefox. It is just a matter of choosing the
    > right window properties in the third argument to window.open. Some
    > combinations seem to force a new window to open, and others will open
    > a tab if that is the user's browser setting.


    Maybe you should create a bug report (search for an existent one before). If
    the user's settings forbid new windows and you can ignore this setting, it's
    obviously a bug. Expect this to be fixed.
     
    Timo Reitz, May 16, 2009
    #5
  6. Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    On May 16, 2:37 am, Timo Reitz <> wrote:
    > Peter Michaux wrote:
    > > I have found a trick in Firefox. It is just a matter of choosing the
    > > right window properties in the third argument to window.open. Some
    > > combinations seem to force a new window to open, and others will open
    > > a tab if that is the user's browser setting.

    >
    > Maybe you should create a bug report (search for an existent one before).If
    > the user's settings forbid new windows and you can ignore this setting, it's
    > obviously a bug. Expect this to be fixed.


    Yes, I do expect it to be fixed and I may log bug reports.

    Regardless, my question still stands. Has anyone found a found a trick
    that currently works to open a new window in IE7/8?

    Peter
     
    Peter Michaux, May 16, 2009
    #6
  7. Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    On May 16, 1:58 am, "rf" <> wrote:
    > Peter Michaux wrote:
    > > I have a question that I've wanted to ask for a long time. Is there
    > > any hack trick to ensure that IE7/8 will open a real new window rather
    > > than a new tab *regardless* of the user's preference settings?

    >
    > Hey, this is *my* browser mate. I'll open stuff in a new window if *I* see
    > fit.
    >
    > It's bad enough you are opening a new tab.


    I think that is a very limited view of how a web page should be built.
    At times a new tab or even a new window is appropriate to the benefit
    of the user.

    I agree that the user's browser preferences should be honoured;
    however, I'm curious if there are any tricks for IE7/8 to force a new
    window even when the user has chosen tabbed browsing.

    Peter
     
    Peter Michaux, May 16, 2009
    #7
  8. John L.

    Doug Miller Guest

    Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    In article <>, Peter Michaux <> wrote:

    >I agree that the user's browser preferences should be honoured;


    Baloney. If you really believed that, you wouldn't ask this question:

    >however, I'm curious if there are any tricks for IE7/8 to force a new
    >window even when the user has chosen tabbed browsing.


    What part of "the user has chosen" are you having difficulty understanding?
     
    Doug Miller, May 16, 2009
    #8
  9. Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    On May 16, 6:47 am, (Doug Miller) wrote:
    > In article <>, Peter Michaux <> wrote:
    >
    > >I agree that the user's browser preferences should be honoured;

    >
    > Baloney. If you really believed that, you wouldn't ask this question:


    Think what you want.

    > >however, I'm curious if there are any tricks for IE7/8 to force a new
    > >window even when the user has chosen tabbed browsing.

    >
    > What part of "the user has chosen" are you having difficulty understanding?


    None.

    Peter
     
    Peter Michaux, May 16, 2009
    #9
  10. John L.

    rf Guest

    Re: Web-page that *BOTH* changes current page + displays a Pop-up page from JavaScript

    Peter Michaux wrote:
    > On May 16, 2:37 am, Timo Reitz <> wrote:
    >> Peter Michaux wrote:
    >>> I have found a trick in Firefox. It is just a matter of choosing the
    >>> right window properties in the third argument to window.open. Some
    >>> combinations seem to force a new window to open, and others will
    >>> open a tab if that is the user's browser setting.

    >>
    >> Maybe you should create a bug report (search for an existent one
    >> before). If the user's settings forbid new windows and you can
    >> ignore this setting, it's obviously a bug. Expect this to be fixed.

    >
    > Yes, I do expect it to be fixed and I may log bug reports.
    >
    > Regardless, my question still stands. Has anyone found a found a trick
    > that currently works to open a new window in IE7/8?


    Persistant bastard, aren't you.

    Your answer is: no.
     
    rf, May 17, 2009
    #10
  11. Re: Web-page that *BOTH* changes current page + displays a Pop-uppage from JavaScript

    Peter Michaux wrote:
    > Thomas 'PointedEars' Lahn wrote:
    >> Yes. Let code in a.html open b.html in a "pop-up window" (could be anything
    >> from the same window to a browser tab).

    >
    > I have a question that I've wanted to ask for a long time. Is there
    > any hack trick to ensure that IE7/8 will open a real new window rather
    > than a new tab *regardless* of the user's preference settings?


    Unlikely, and if there would be a way, that must be considered a bug to be
    fixed soon; nothing to rely on. That is why they are called *user*
    preferences. Of course, you can always deploy a IEAK-based Web application
    where such restrictions might not apply.

    > I have found a trick in Firefox. It is just a matter of choosing the
    > right window properties in the third argument to window.open. Some
    > combinations seem to force a new window to open, and others will open
    > a tab if that is the user's browser setting.


    The probability that a new window is opened instead of a new tab or the
    document being loaded into the same tab, increases if you provide the
    `width' and `height' parameters in the third argument of window.open().
    Be sure to provide the `resizable' and `scrollbars' parameters also.

    In addition, several user agents also have methods for dialog windows, e.g.
    window.openDialog() in Gecko-based and window.showModalDialog() in both
    Gecko-1.9+ and MSHTML-4.0+-based UAs.

    <https://developer.mozilla.org/en/DOM/window.open>
    <https://developer.mozilla.org/en/DOM/window.openDialog>
    <https://developer.mozilla.org/en/DOM/Window.showModalDialog>
    <http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx>

    With Internet Explorer 7+, be aware that if popup windows are blocked by
    default, the user needs to reload the document in order to show the popup
    eventually.

    > [...]
    > If anyone has found any trick, especially for IE, I'd be interested to
    > know about it even if it is a hack.


    Script-kiddies rely on tricks to achieve what *they* want in spite of the
    available evidence; responsible developers reconsider the design of their
    application so that, within the capabilities of the UA, it suits the needs
    of the *user* best.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 18, 2009
    #11
    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. Chumley Walrus
    Replies:
    1
    Views:
    12,186
    =?Utf-8?B?QnJpYW4gQnJvd24=?=
    Dec 16, 2004
  2. ABCL
    Replies:
    0
    Views:
    555
  3. Cindy
    Replies:
    2
    Views:
    81
    Stephen Poley
    Jul 3, 2003
  4. Cindy
    Replies:
    1
    Views:
    82
    Stephen Poley
    Jul 4, 2003
  5. Replies:
    3
    Views:
    388
Loading...

Share This Page