[thelist] Need Javascript help with a pop-up window

.jeff jeff at members.evolt.org
Sat Sep 1 11:26:39 CDT 2001


amy,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Amy Roberts
>
> [...] I need to know how to bring the open window to
> the front when the next word is clicked on that uses
> the same link
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

simple, in your openWindow() function, check that the browser supports the
focus() method of the window object (not all do), and if so focus the new
window.

function openWindow()
{
  var href = '../info/words_tips.html';
  var target = 'remote';
  var features = 'resizable,width=300,height=600,left=700,top=0';
  popupWin = window.open(href, target, features);
  if(popupWin.focus) popupWin.focus();
}

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> <a href="javascript:openWindow();online">word</a>
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

what's the purpose of the variable after calling the openWindow() function?

also, fwiw, you've made your information unnecessarily inaccessible to
non-js users.  i'd restructure the link to give everyone access to the
information.

start by changing the function alittle so you can pass the path of the
document and target name of the window.

function openWindow(href, target)
{
  var features = 'resizable,width=300,height=600,left=700,top=0';
  popupWin = window.open(href, target, features);
  if(popupWin.focus) popupWin.focus();
}

now, change your links so they use the onclick event handler to call the
openWindow() function.  include href and target attributes with the values
originally from the function.

<a
 href="../info/words_tips.html"
 target="remote"
 onClick="openWindow(this.href, this.target); return false"
>word</a>

non-js users will get the information in a regular new window.  js-enabled
users will get it in a javascript popup.

here's some reading if you don't understand what the "return false"
statement accomplishes in the onclick event handler:

JavaScript: The Point of No Return?!
http://evolt.org/article/thelist/17/8869/

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list