Re: Problem with window.open in Firefox



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
.



Relevant Pages

  • Re: strange cursor behavior in gnome terminal
    ... I had some xterm escape sequences to set the window title. ... Marius Gedminas ...
    (Ubuntu)
  • Re: Santa Bill McReynolds
    ... better and logical escape point, and it WAS found that way. ... suitcase there as part of staging doesn't fit. ... then putting the suitcase under the window to ... the basement window you are talking about was not difficult to ...
    (alt.true-crime)
  • Re: How come we no no see police or army cordon those forested area...you mean the MS issue over ah?
    ... men to go after those monkeys ... window, he would not probably been able to jump over a double fencing ... they had used a young man to re-enact the escape is a farce. ...
    (soc.culture.singapore)
  • Re: loop never exits on ESC
    ... > I tried ur code but have not got any wait window when i pressed ESC :-( ... >> WINDOW for about .5 second each time you press escape. ... >>>>> ENDIF ...
    (microsoft.public.fox.programmer.exchange)
  • Re: resizable broken in Tk 804.027?
    ... But with Tk 804.027, the resize method gives incorrect output, and the ... window is resizable (actually, you can enlarge it but not shrink it): ... no manual resizability at all. ...
    (comp.lang.perl.tk)