f



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

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.
0
5/15/2009 5:22:17 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

10 Replies
1582 Views

Similar Articles

[PageSpeed] 1

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
0
Thomas
5/15/2009 6:21:16 PM
On May 15, 11:21 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
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
0
Peter
5/16/2009 5:02:26 AM
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.


0
rf
5/16/2009 8:58:32 AM
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.
0
Timo
5/16/2009 9:37:06 AM
On May 16, 2:37=A0am, Timo Reitz <godsb...@arcor.de> 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, i=
t'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
0
Peter
5/16/2009 1:18:25 PM
On May 16, 1:58=A0am, "rf" <r...@z.invalid> 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* se=
e
> 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
0
Peter
5/16/2009 1:22:31 PM
In article <4bad0189-44c8-40c3-82e7-f38bfdd8a348@p6g2000pre.googlegroups.com>, Peter Michaux <petermichaux@gmail.com> 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?
0
spambait
5/16/2009 1:47:12 PM
On May 16, 6:47=A0am, spamb...@milmac.com (Doug Miller) wrote:
> In article <4bad0189-44c8-40c3-82e7-f38bfdd8a...@p6g2000pre.googlegroups.=
com>, Peter Michaux <petermich...@gmail.com> 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 understandin=
g?

None.

Peter
0
Peter
5/16/2009 1:52:16 PM
Peter Michaux wrote:
> On May 16, 2:37 am, Timo Reitz <godsb...@arcor.de> 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. 


0
rf
5/16/2009 11:04:22 PM
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
0
Thomas
5/18/2009 9:27:08 AM
Reply: