Grant Wagner <gw*****@agricoreunited.com> wrote in message news:<40***************@agricoreunited.com>...
Mike wrote:
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;">
...
Thanks,
Mike
<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>
Once you have convinced yourself that the function is firing and
directing the browser to Yahoo!, you can begin to work on what is most
likely the real problem, which is that the "work" your script is doing
to build the URI is probably building an *incorrect* URI, or the code
itself has a syntax error. The way to confirm this is to use:
...
Thank you very much for the speedy reply with advice and
pointers to the other info.
Perhaps I should first clarify what I mean by "clicking the browser
option to open in a new window." By this I mean, with IE or NS, I
right click on the <a> object, and select "Open Link in New Window"
from pulldown.
Do I need to detect this differently than via onClick. Do I need
to detect the right mouse, and then figure out which of the pulldown
elements they asked for?
In any case, I did try your suggestion. Here is the exact code I ran:
<html>
<head>
<script type="text/javascript">
function NewPage() {
alert('here');
window.location.href = 'http://www.yahoo.com';
}
</script>
</head>
<body>
<a href="noJS.htm" onClick="NewPage(); return false;">CLICK</a>
</body>
</html>
If I open in the same window, the alert shows up and I get
to yahoo. If I open in new window (as described above) then it
does NOT fire the function, and just tries to open noJS.htm.
I also now see that in IE, if I right click on the <a> object,
and then select "Open Link" (which should then open it in the
same window), this also DOES NOT fire the function. It seems
that only the left mouse causes onClick to occur.
Thanks again. And sorry if I am being dense.
Mike