Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

href="javascript:myfunction()" does not work on Netscape?

Status
Not open for further replies.

rzward

Programmer
Nov 6, 2002
38
US
Hello,

I am trying to have a link call my JavaScript function and have it work for all Internet Explorer and Netscape browsers. I have read that this can be accomplished by:

<a href=&quot;javascript:myfunction()&quot;>Click me</a>

where myfunction has already been defined inside <head>.

This works using IE but unfortunately doesn't work using NS 4.7 or NS 7.1. What appears to work using NS 4.7 and 7.1 is:

<a href=&quot;javascript:{;}&quot; onclick=&quot;myfunction()&quot;>Click me</a>

Is the second approach a good one or is there a more universal way of doing this that works for all browsers?

Thank you in advance for any help.

Richard
 
<a href=&quot;javascript:void(0)&quot; onclick=&quot;return myfunction()&quot;>Click me</a>
and
<a href=&quot;#&quot; onclick=&quot;return myfunction()&quot;>Click me</a>
and
<a href=&quot;&quot; onclick=&quot;return myfunction()&quot;>Click me</a>

works fine in NN6.2+

____________________________________________________
[sub]Python????? The other programming language you never thought of!
thread333-584700[/sub]
onpnt2.gif
 
onpnt,

Thank you for your reply.

Is &quot;return&quot; required? Or is it good style to have &quot;return myfunction()&quot; instead of just &quot;myfunction()&quot;? Is there a place where I can read about this?

Richard
 
Thank you for directing me to the reading. I have a better understanding now.

Richard
 
Thank you again for the pointer.

However, in order to avoid any possible confusion about the language, shouldn't the tags be:

<a href=&quot;javascript:void(0)&quot; onclick=&quot;javascript:{statement1;statement2;return false;}&quot;>

or

<a href=&quot;javascript:void(0)&quot; onclick=&quot;javascript:{return myfunction ();}&quot;>

This would avoid the possibility of the browser using some other language? Am I wrong?

Richard
 
Hello there:

My problem is kind like yours, first my function did not work in Netscape, but when I could achieved to work in Netscape, a certain line did not response. I think my problem is that I am trying to open a file which resides in a local drive. If I do this through <a hre= &quot;file:///...&quot;> it works fine, but I also need to sent through a value in a variable, so I can not only use an href tag because my javacript variable is not sent, but if I use javascript the netscape browser says &quot;illegal URL method 'file:'&quot;.

Do you have any ideas, why this is happening... or how I can achieve to open a local file and send a variable at the same time with another method??

Please help...

thanks in advance.

Liliana
 
I'm not sure if I can help you but the following works on both Netscape and IE browsers:

<a href=&quot;#&quot; onClick=&quot;JavaScript:{myForm.myHiddenField.value=1;myForm.action+='#Test';myForm.mySubmitButton.click();return
false;}&quot;>

myForm is the name of the form, myHiddenField is a hidden field already on the form, #Test is an anchor on the next page that will be displayed and mySubmitButton is the submit button on the current page.

Using the onClick handler, I'm able to assign values, call JavaScript functions, etc.

I found that Netscape 7.1 and IE do different things with the href and that using the # for the href works for both.

Richard
 
Thanks a lot Richard,

I have realized that my problem is not the fuction itself but the method &quot;file:///C|...&quot;. this kind of method is illegal for netscape, it´s a fact of security.

so definitly javascript is not the option.

Thanks a lot again.

Liliana
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top