By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

Problem with window.open in Firefox

P: n/a
Hello

The window.open method brings my window to the top only if it is new. If
it's being reused, the window does not come to the foreground (with IE 6 it
does).

Is there a new way in Mozilla/Firefox that I can ensure that this
window comes to the top?

Thank you for your help
Jan 10 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
tochiromifune escreveu:
Is there a new way in Mozilla/Firefox that I can ensure that this
window comes to the top?


Call the focus method "yourWindow.focus()" :b
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 10 '06 #2

P: n/a
"Jonas Raoni" <jo********@gmail.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
tochiromifune escreveu:
Is there a new way in Mozilla/Firefox that I can ensure that this
window comes to the top?


Call the focus method "yourWindow.focus()" :b


This is what I do but the focus method does not work in Firefox. Here is
the code:

function openFromLink(town) {
selectedCity = town
theURL = "seetown.php?select=" + selectedCity
newWindow = window.open(theURL,"infoWin","width=800,height=600 ")
if (window.focus) {
newWindow.focus()
}
}

This function is implemented this way:
<a href="javascript:openFromLink('London')">London</a>

The focus works in IE but not in Firefox.
Jan 10 '06 #3

P: n/a
Lee <RE**************@cox.net> wrote in news:dq*********@drn.newsguy.com:
tochiromifune said:
This function is implemented this way:
<a href="javascript:openFromLink('London')">London</a>

The focus works in IE but not in Firefox.


It's because you're abusing the javascript: pseudo-protocol.
The focus() method is working, but the main window immediately
takes focus back as the link is activated.

<a href="seetown.php?select=London"
onclick="openFromLink('London');return false">London</a>


I tried your way but it does not work either. Also I do not understand
what you explain: the link should be activated before the javascript
function is executed...?
Jan 11 '06 #4

P: n/a
tochiromifune wrote :
"Jonas Raoni" <jo********@gmail.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:

tochiromifune escreveu:
Is there a new way in Mozilla/Firefox that I can ensure that this
window comes to the top?

Make sure that Tools/Options.../Content tab/Advanced... button/Allow
Scripts to:/Raise or lower existing windows checkbox is checked

More on this:

http://www.gtalbot.org/Netscape7Sect...seLowerSetting


Call the focus method "yourWindow.focus()" :b

This is what I do but the focus method does not work in Firefox. Here is
the code:

function openFromLink(town) {
selectedCity = town


Why create an extra local variable?
theURL = "seetown.php?select=" + selectedCity
newWindow = window.open(theURL,"infoWin","width=800,height=600 ")
You first need to check the existence of the window reference and its
closed prroperty.
if (window.focus) {
newWindow.focus()
That's not the correct way to call the focus() command. If the window is
new, then, as you say yourself, you do not need to make the focus()
call. On the other hand, if the window exists and if the url is the same
(and you have to check, verify this first, to begin with), then you must
make the focus call on the window reference.

For a practical and recommendable example on all this, see

http://developer.mozilla.org/en/docs...Best_practices

and see the example where a single secondary window is used and where
such single secondary window is reused for other links.
}
}

This function is implemented this way:
<a href="javascript:openFromLink('London')">London</a>

"javascript:" pseudo-protocol links are widely known to cause all kinds
of problems and are not recommendable.

http://jibbering.com/faq/#FAQ4_24

http://developer.mozilla.org/en/docs.....29.22_....3E


The focus works in IE but not in Firefox.


It does work in Fx if you allow "Raise or lower existing windows" and if
your code acts accordingly.

http://developer.mozilla.org/en/docs/DOM:window.open

Gérard
--
remove blah to email me
Jan 12 '06 #5

P: n/a
Gérard Talbot wrote:
tochiromifune wrote :
function openFromLink(town) {
selectedCity = town
Why create an extra local variable?


It would be a global, not local one. There is no reason why besides missing
knowledge; the author should have used the `var' keyword to make it local:

function ...(...)
{
var selectedCity = town;
}

One valid reason to copy an argument's value this way is to modify the value
but use the argument's original value later. However, that does not happen
here; so the line is redundant, indeed.
theURL = "seetown.php?select=" + selectedCity
newWindow = window.open(theURL,"infoWin","width=800,height=600 ")


You first need to check the existence of the window reference and its
closed prroperty.


Absolutely true. And `theURL' and `newWindow' should be declared locals
(at least `theURL' should), where `theURL' is in fact redundant:

var newWindow = window.open(
"seetown.php?select=" + selectedCity,
"infoWin",
"width=800,height=600");

This is of course still potentially harmful: there is no guarantee that the
window can be opened with that dimensions or that they make sense anyway.
Especially, the new window would lack scrollbars and the feature of
resizability which in combination is certainly a Bad Thing. And all URI
components should be properly escaped. So I propose

function isMethodType(s)
{
return (s == "function" || s == "object");
}

var esc = (isMethodType(typeof encodeURIComponent)
? encodeURIComponent
: (isMethodType(typeof escape)
? escape
: function(s) { return s; }));

var newWindow = window.open(
"seetown.php?select=" + esc(selectedCity),
"infoWin",
"resizeable,scrollbars");

instead. The size of the new window is determined by the UA, which should
follow what the user configured; it is resizable by the user and has
scrollbars in case the dimensions of the desktop do not suffice for the
user to resize the window large enough. And the URI component is properly
escaped.
if (window.focus) {
newWindow.focus()


That's not the correct way to call the focus() command.


Actually, it is a method that is called. And it is a way I would consider
to be correct (it is not logical to assume that if one Window object has
the `focus' property, another, newly created one, would have not -- or have
you empirical proof of the opposite?), although the feature test allows for
improvement.

I would write

if (newWindow
&& !newWindow.closed
&& isMethodType(typeof newWindow.focus))
{
newWindow.focus();
}
If the window is new, then, as you say yourself, you do not need to make
the focus() call.


Not true. If there was already a window with the same name ("infoWin"),
its content only has changed due to window.open() but it is unlikely to be
focused already. So it is a Good Thing to try to set the focus to it.
PointedEars
Jan 12 '06 #6

P: n/a
Thomas 'PointedEars' Lahn wrote :
Gérard Talbot wrote:
tochiromifune wrote :
function openFromLink(town) {
selectedCity = town Why create an extra local variable?


It would be a global, not local one. There is no reason why besides missing
knowledge; the author should have used the `var' keyword to make it local:

function ...(...)
{
var selectedCity = town;
}

One valid reason to copy an argument's value this way is to modify the value
but use the argument's original value later. However, that does not happen
here;

So why bring this up in your reply then?

so the line is redundant, indeed.
So, according to you, creating an extra variable - oh yeah, a *_local_*
one - in the OP's case was unneeded, pointless, right?
theURL = "seetown.php?select=" + selectedCity
newWindow = window.open(theURL,"infoWin","width=800,height=600 ") You first need to check the existence of the window reference and its
closed prroperty.


Absolutely true. And `theURL' and `newWindow' should be declared locals
(at least `theURL' should), where `theURL' is in fact redundant:

var newWindow = window.open(
"seetown.php?select=" + selectedCity,
"infoWin",
"width=800,height=600");

This is of course still potentially harmful: there is no guarantee that the
window can be opened with that dimensions or that they make sense anyway.
Especially, the new window would lack scrollbars and the feature of
resizability which in combination is certainly a Bad Thing. And all URI
components should be properly escaped. So I propose

function isMethodType(s)
{
return (s == "function" || s == "object");
}

var esc = (isMethodType(typeof encodeURIComponent)
? encodeURIComponent
: (isMethodType(typeof escape)
? escape
: function(s) { return s; }));

var newWindow = window.open(
"seetown.php?select=" + esc(selectedCity),
"infoWin",
"resizeable,scrollbars");

It's "resizable", not "resizeable". If you write "resizeable", then the
new window will not be resizable.

instead. The size of the new window is determined by the UA, which should
follow what the user configured; it is resizable by the user and has
scrollbars in case the dimensions of the desktop do not suffice for the
user to resize the window large enough. And the URI component is properly
escaped.
if (window.focus) {
newWindow.focus() That's not the correct way to call the focus() command.


Actually, it is a method that is called.

Useless nitpicking, just nit-picking on semantic.
And it is a way I would consider to be correct (it is not logical to assume that if one Window object has
the `focus' property, another, newly created one, would have not -- or have
you empirical proof of the opposite?), although the feature test allows for
improvement.

I would write

if (newWindow
&& !newWindow.closed
&& isMethodType(typeof newWindow.focus))
{
newWindow.focus();
}

This kind of code (complete code, complete example) was already provided
at the url I mentioned in my earlier post. Your reply brings very little.

If the window is new, then, as you say yourself, you do not need to make
the focus() call.


Not true. If there was already a window

Read yourself what's up there. I say "If the window is new" and your
answer/reply starts with "If there was already a window". We're not
talking about the same thing.

Gérard
Jan 12 '06 #7

P: n/a
Gérard Talbot wrote:
Thomas 'PointedEars' Lahn wrote :
Gérard Talbot wrote:
tochiromifune wrote :
function openFromLink(town) {
selectedCity = town
Why create an extra local variable? It would be a global, not local one. There is no reason why besides
missing knowledge; the author should have used the `var' keyword to make
it local:

function ...(...)
{
var selectedCity = town;
}

One valid reason to copy an argument's value this way is to modify the
value but use the argument's original value later. However, that does
not happen here;


So why bring this up in your reply then?


Because it is important to know that it is not needless always.
so the line is redundant, indeed.


So, according to you, creating an extra variable - oh yeah, a *_local_*
one - in the OP's case was unneeded, pointless, right?


I eventually confirmed your assessment of that line, no longer considering
the wrong term you used, yes.
[...]
var newWindow = window.open(
"seetown.php?select=" + esc(selectedCity),
"infoWin",
"resizeable,scrollbars");
It's "resizable", not "resizeable". If you write "resizeable", then the
new window will not be resizable.


True.
[...]
if (window.focus) {
newWindow.focus()
That's not the correct way to call the focus() command. Actually, it is a method that is called.


Useless nitpicking, just nit-picking on semantic.


No, it is important to know your terms. A method is always associated
with an object; a command is not. Commands are executed, not called.
And it is a way I would consider


Please learn to quote, especially trim your quotes to the
_minimum_ required to retain context.

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
to be correct (it is not logical to assume that if one Window object has
the `focus' property, another, newly created one, would have not -- or
have you empirical proof of the opposite?), although the feature test
allows for improvement.

I would write

if (newWindow
&& !newWindow.closed
&& isMethodType(typeof newWindow.focus))
{
newWindow.focus();
}

This kind of code (complete code, complete example) was already provided
at the url I mentioned in my earlier post. Your reply brings very little.


My reply includes a quite reliable feature test, an important cornerstone in
reliable DOM scripting; the examples you provided the URL for do not (yet).
If the window is new, then, as you say yourself, you do not need to make
the focus() call.


Not true. If there was already a window


Read yourself what's up there. I say "If the window is new" and your
answer/reply starts with "If there was already a window". We're not
talking about the same thing.


You can _never_ be sure that a window is new, and the source code provided
by the OP does not indicate it has to be. In fact, the OP's problem was
that the window was _not_ new which is why he wanted to focus the changed
one. You misunderstood.
PointedEars
Jan 12 '06 #8

P: n/a
Thomas 'PointedEars' Lahn wrote :
Gérard Talbot wrote:
Thomas 'PointedEars' Lahn wrote :
Gérard Talbot wrote:
tochiromifune wrote :
> function openFromLink(town) {
> selectedCity = town
Why create an extra local variable?
It would be a global, not local one. There is no reason why besides
missing knowledge; the author should have used the `var' keyword to make
it local:

function ...(...)
{
var selectedCity = town;
}

One valid reason to copy an argument's value this way is to modify the
value but use the argument's original value later. However, that does
not happen here;

So why bring this up in your reply then?


Because it is important to know that it is not needless always.
so the line is redundant, indeed.

So, according to you, creating an extra variable - oh yeah, a *_local_*
one - in the OP's case was unneeded, pointless, right?


I eventually confirmed your assessment of that line, no longer considering
the wrong term you used, yes.
[...]
var newWindow = window.open(
"seetown.php?select=" + esc(selectedCity),
"infoWin",
"resizeable,scrollbars");

It's "resizable", not "resizeable". If you write "resizeable", then the
new window will not be resizable.


True.
[...]
> if (window.focus) {
> newWindow.focus()
That's not the correct way to call the focus() command.
Actually, it is a method that is called.

Useless nitpicking, just nit-picking on semantic.


No, it is important to know your terms. A method is always associated
with an object; a command is not. Commands are executed, not called.

It is always better to use terms at their best but I won't report or
annoy the poster unless such misuse is important or has important
misunderstanding consequences. Here, it definitely was not. You, Thomas
Lahn, you do this all the time, regardless of context. You can't expect
people nor demand to people to write perfect english in a javascript
newsgroup, like writing a revised+proofread javascript book.

Your nitpicking habits are not necessarly constructive; I'd say they are
more annoying than anything. And your own website is not a model of the
kind of preaching + relentless nitpicking that you practice either. You
have been one of the most vocal person in this newsgroup during years in
blatant and complete contradiction in an embarassing number of areas
(markup validation failures, use of frames, deprecated attributes,
etc.). You demand and have been demanding to others what you haven't
been doing yourself during years. You annoy people with details and
minor issues when your own website has been a failure in large areas.

You've been telling people during years (and you still do) to replace
language="javascript" with type="text/javascript" in this newsgroup but
you can not and could not even do it on your own website during years!

You tell people very often to learn how to quote, how to use google, how
to do this or that but the thing is you do not even code the way you
demand others to code.

Gérard
--
remove blah to email me
Jan 12 '06 #9

P: n/a
Gérard Talbot <ne***********@gtalbot.org> wrote:

$ telnet -- mail.gtalbot.org smtp
| Trying 67.15.2.61...
| Connected to mail.gtalbot.org.
| Escape character is '^]'.
| 220 srv19.shieldhost.com ESMTP Sendmail Secured/EZSM; Thu, 12 Jan 2006
| 13:54:23 -0600
| [...]
| RCPT TO:<ne***********@gtalbot.org>
| 550 5.1.1 <ne***********@gtalbot.org>... User unknown
| RCPT TO:<ne*******@gtalbot.org>
| 559 5.7.1 Message from [...] rejected - see http://njabl.org/
[flame]


<URL:http://www.zedat.fu-berlin.de/services/rules.html>

[x] ab***@uni-berlin.de
[x] Score adjusted
[x] Followup-to: poster
PointedEars
Jan 12 '06 #10

P: n/a
Thomas 'PointedEars' Lahn said the following on 1/12/2006 9:10 AM:

<snip>
You can _never_ be sure that a window is new


Quite to the contrary my friend.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 12 '06 #11

P: n/a
Thomas 'PointedEars' Lahn wrote:
[snip nitpicking]
[flame]

On the contrary, there were no flames present. Just a very good point. You
don't practice what you preach. Leading by example is much harder than
leading by words.

Perhaps if you questioned yourself about why your own work doesn't represent
the ideals that you seem to preach, you might be more sympathetic and
understand of others.

I'm reminded of the quote from the movie Silence Of The Lambs:
"You see a lot, Dr. Quinn. But are you
strong enough to point that high-powered
perception at yourself? How about it...?
Look at yourself and write down the truth.
Or maybe you're afraid to."
[x] Score adjusted


What does this even MEAN, why would anyone CARE, and why must you ANNOUNCE
your personal actions?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jan 12 '06 #12

P: n/a
Thomas Lahn,

Anyone can verify all by himself my claims directed and regarding your
very own site and your admonishing+nitpicking manners.
You have been preaching in this newsgroup during years about valid
markup code, validating webpages, etc.. but your own website fails
miserably and has been failing miserably for years to comply with your
own preaching standards.

Anyone can go to the WDG validator site and verify this:
http://www.htmlhelp.com/cgi-bin/vali...&hidevalid=yes
Validation of http://pointedears.de/scripts/

http://www.htmlhelp.com/cgi-bin/vali...&hidevalid=yes

1102 markup errors out of 100 pages.

You use frames, you use deprecated attributes hundreds of times, you use
deprecated elements, you don't even use a strict DTD, etc,etc, etc..

Anyone can verify for himself my claims here.

Your site is exactly the opposite of what you admonishingly reproach in
other's code. You have been told this before in this newsgroup and you
have continued to ignore such call to become yourself consequent,
coherent. So, the logical conclusion should be that you are an
hypocritical, some sort of a deliberate liar, a cheater.

You practice the reverse of what you demand to others. You deny what you
demand to others. You refuse to comply with your own demands to others.
Gérard
--
remove blah to email me
Jan 12 '06 #13

P: n/a
VK

tochiromifune wrote:
The focus works in IE but not in Firefox.


Pop-ups and Pop-unders are considered to be one of so-called "Common
Annoyances" in Firefox and they have damn good reasons to think so (me
too).

In Firefox:
1) Tools > Options...
2) Switch on "Content" tab
3) Uncheck "Block Popup Windows"
4) In "Enable JavaScript" section click "Advanced"
5) Check "Raise or lower windows"

Now your Firefox is vulnerable against popup advertisers of all kinds.
And you script should work too - but you can realize how useless it can
be on a real run.

P.S. Do not forget to put default settings back for your own good! ;-)

Jan 12 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.