[thelist] Javascript Woes

jeff jeff at members.evolt.org
Tue Feb 20 00:22:22 CST 2001


salvatore,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Salvatore Palmisano
:
: Ok Ive modifed this a bit to use a separate
: function call, as the intID has to be different
: for each link on the page:
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

good idea.  however, may i suggest you take this a step further so that it
will work for non-js users as well.  instead of using a javascript link,
create a standard link in the href attribute of the <a> tag and call your
function that opens a js popup in the onClick event handler, passing the
value of the href into the popup via the function and then issuing a return
false to cancel the href for js users.  is that too much to handle all in
one sentence?  *grin*  take this link as an example:

<a
 href="page.asp?id=4"
 target="newWin"
 onClick="openWin(this.href, this.target); return false"
>View Item #4</a>

your function looks like this:

function openWin(url, target)
{
  features = 'resizable,width=385,height=295';
  myWindow = window.open(url, target, features);
  if(myWindow.focus) myWindow.focus();
}

i added alittle bit in the function to check for support of the focus method
on the window object and if supported to go ahead and focus the window.
this will make it so that if the window is pushed behind the main window and
the user clicks a link, it will bring that popup back to the front instead
of continuing to hide out behind the main window confusing the user.

the result is non-js users will get a new browser window (thanks to the
target attribute) with the appropriate data.  js users will get a sized
popup with the same page.  this way no one is left out.  those with js
enabled get a better experience.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: function events(intid)
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

events is a reserved word in javascript.  i would suggest that you think of
another name for this function.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I guess the question remains: how can I
: reference the intid passed to the function?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

you've already created an argument (intid) in the function definition to
contain that value.  you can retrieve that value from within the function by
using that variable name (intid).

'page.asp=' + intid;

good luck,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list