Problem with window.open in Firefox

T

tochiromifune

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
 
J

Jonas Raoni

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
 
T

tochiromifune

tochiromifune escreveu:

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:eek:penFromLink('London')">London</a>

The focus works in IE but not in Firefox.
 
L

Lee

tochiromifune said:
This function is implemented this way:
<a href="javascript:eek:penFromLink('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>
 
T

tochiromifune

Lee said:
tochiromifune said:


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

Gérard Talbot

tochiromifune wrote :
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/Netscape7Section/Popup/PopupAndNetscape7.html#RaiseLowerSetting

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/DOM:window.open#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:eek:penFromLink('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/doc...D.22javascript:window.open.28....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
 
T

Thomas 'PointedEars' Lahn

Gérard Talbot said:
tochiromifune wrote :

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

Gérard Talbot

Thomas 'PointedEars' Lahn wrote :
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?
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.


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.

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
 
T

Thomas 'PointedEars' Lahn

Gérard Talbot said:
Thomas 'PointedEars' Lahn wrote :

So why bring this up in your reply then?

Because it is important to know that it is not needless always.
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.

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

Gérard Talbot

Thomas 'PointedEars' Lahn wrote :
Gérard Talbot said:
Thomas 'PointedEars' Lahn wrote :
So why bring this up in your reply then?

Because it is important to know that it is not needless always.
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
 
T

Thomas 'PointedEars' Lahn

M

Matt Kruse

Thomas said:
[snip nitpicking]

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

Gérard Talbot

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/val...rnings=yes&input=yes&spider=yes&hidevalid=yes


Validation of http://pointedears.de/scripts/

http://www.htmlhelp.com/cgi-bin/val...rnings=yes&input=yes&spider=yes&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
 
V

VK

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! ;-)
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top