[thelist] href=# versus href=JavaScript.....

Ben Henick persist1 at io.com
Wed Feb 21 22:27:58 CST 2001


On Wed, 21 Feb 2001, N at ta$ wrote:

> I use the '#' system myself and have a question since this issue got me
> thinking...
> 
> I visited one of my more recent site and am curious:
> 
> My current anchor code is:
> 
> <A HREF="#"
> onClick="window.open...

In your shoes I probably wouldn't've shared the target URL for the
window.open(), but that's a whole different thread.  *chuckle*

When you write "href='#'" you are saying, "move the page so that the
anchor called '' (an empty string) is at the top of the browser window."

Thus somewhere on your page there needs to be:

<a name=""></a>

The few times I've done this I've always used the convention #top, so that
there's no ambiguity.

The take-no-prisoners approach to this would be to write your HREFs to the
images (in the same menu), and then putting the following code behind an
onload statement:

for (i = x; i < y; i++)
{
  document.links[i].href="javascript:NewWinFunction(" + i + ")";
}

// x == the index of the first HREF you want to change
// y == the index+1 of last HREF you want to change
// i also eq array indices containing the URLs you want to load into
// the new window

The argument passed to NewWinFunction references the array, which then
tells the window.open() statement which URL to load, as in:

NewWin = window.open(PageToLoad[z],"SecondWindow","...");
// z == the name of the argument referenced in your function statement

If you want to be really gnarly, you also put the entire
'document.links...' code inside of an if statement that only allows it to
work for browsers that reliably support window.open()... note that AOL,
WebTV, and several older versions of IE3 DON'T support window.open().


-- 
Ben Henick
Web Author At-Large
http://www.io.com/persist1/
persist1 at io.com

"Are you pondering what I'm pondering, Pinky?"
"I think so, Brain, but... (snort) no, no, it's too stupid."
"We will disguise ourselves as a cow."
"Oh!" (giggles) "That was it exactly!"





More information about the thelist mailing list