Here's a (partial) solution to my original post.
ORIGINAL GOAL: Provide a hyperlink which calls a javascript
function to create a new URL, which will work whether clicked
with the left mouse, or the right mouse context menu (e.g., to
open the URL in a new tab or a new window).
SOLUTION: This requires (1) detecting the right mouse click in
addition to the left, and (2) javascript function must set the
element.href and then return "true" (which allows the context
menu to work as normal, and then if the user does elect to open
the link, it will follow the replaced href).
The following works for at least IE6, NS7.1, Mozilla 1.6, but
not Opera. I can't see how to detect the right mouse click in
Opera, so if the user right clicks to open new page or window,
they will get noJS.htm. I did not try this with a Mac.
<script type="text/javascript">
function NewPage(element) {
// create desired URI and assign to the element's href.
target = "http://www.yahoo.com"
element.href = target;
}
</script>
...
<a href="noJS.htm"
onClick= "NewPage(this); return true;"
oncontextmenu="NewPage(this); return true;"> ... </a>
Mike
zeleznik@comcast.net (Mike) wrote in message news:<484ca2e9.0404301525.34c8b501@posting.google. com>...[color=blue]
> After referring to the IE DOM reference that Grant Wagner
> pointed out in his followup, I see that the onClick event
> only applies to the LEFT mouse button. There is another event
> for the RIGHT context menu button (which I was using to get
> the new window).
> ...
> Those pointers to the DOM referencese are a big help (I left
> them in the inclusion below).
> Thanks!
> Mike
>
> Grant Wagner <gwagner@agricoreunited.com> wrote in message news:<40926946.1FF32559@agricoreunited.com>...[color=green]
> > Mike wrote:
> >[color=darkred]
> > > In my previous post, I wrote:
> > > > ...
> > > > GOAL: (very simple) Provide a hyperlink which, when clicked,
> > > > calls a javascript function which opens a new URL.
> > > > ...
> > > > PROBLEM: The following code works fine if I click to open in
> > > > the same window, but if I click the browser option to open in a
> > > > new window, the new window tries to open the href URL (the
> > > > onClick function does get executed, but seems to be ignored).
> > > > ...
> > > > <script language="javascript">
> > > > function NewPage() {
> > > > location.href = "/cgi-bin/page1.pl";
> > > > }
> > > > </script>
> > > > ...
> > > > <a href="noJS.htm" onClick="NewPage(); return false;">
> > > > ...
> > > ...[/color]
> > <a href="noJS.htm" onclick="NewPage();return false;">
> >
> > is the way to do it. I suggest you try it with:
> >
> > <script type="text/javascript">
> > function NewPage() {
> > alert('here');
> > window.location.href = 'http://www.yahoo.com';
> > }
> > </script>
> > ...
> >| Grant Wagner <gwagner@agricoreunited.com>
> >
> >* Client-side Javascript and Netscape 4 DOM Reference available at:
> >*
> >
http://devedge.netscape.com/library/...ce/frames.html
> >
> >* Internet Explorer DOM Reference available at:
> >*
> >
http://msdn.microsoft.com/workshop/a...ence_entry.asp
> >
> >* Netscape 6/7 DOM Reference available at:
> >*
http://www.mozilla.org/docs/dom/domref/
> >* Tips for upgrading JavaScript for Netscape 7 / Mozilla
> >*
http://www.mozilla.org/docs/web-deve...upgrade_2.html[/color][/color]