473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with window.open in Firefox

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
13 22138
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
"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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jiri Brada | last post by:
Hi, I have got a following problem with using Javascript: I have a HTML page with pictures' thumbnails. After clicking on any thumbnail, I would like to open a new window with the original...
8
by: Dominic Tocci | last post by:
I'm searching for a way to use window.open on my web page to open a window in firefox that allows the sidebars to work (bookmarks, history, etc). When I use the following: var...
23
by: Markus | last post by:
Hi, i have this problem: Sometimes, i can't reproduce, if i click on an small image on the website, the popup _AND_ an other Tab in firefox open. Here are the linkcode: <div...
4
by: Csaba Gabor | last post by:
Up until a few weeks ago, javascript code like window.open("http://mydomain.com", "windowName"); would always bring my new or reused window to the top, with focus. Lately, Firefox (Deer park...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
3
by: BoBi | last post by:
Hi, See the following URL for the concerned page: http://home.scarlet.be/kenya-belgium/list_2_en/a_kenyan_cat_and_a_belgian_cat.html Clicking on "Menu" or "Publication" in the right upper...
4
by: arajunk | last post by:
In Firefox this opens a full size window (maximized) . In IE it opens the partial window requiring user to click restore (upper right) to maximize. What am I missing ? var...
4
by: deBaer | last post by:
Hi! For an in-house web application (it will only be deployed on Firefox browsers with JavaScript turned on), I need to open a preview window (which needs to be a separate window, even if...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.