Solved

How to trigger onclick event in NS4 ?

Posted on 2002-07-23
9
301 Views
Last Modified: 2007-11-27
Hi,

I have in my page a "A" tag with an onclick event associated.  I would like to programatically trigger this onclick event.  I do that with the following block of code. It works with IE but not with netscape 4. When i try that code with netscape 4 I have the following error message "mnuTop_2 has no properties !"
Thanks in advance.

Guillaume.


if (ns4==1)
{
   obj = document.layers["divSlideCont"]
   obj = obj.layers["divSlide1"]          
   obj.mnuTop_2.onclick()
}
else
{
   sName = "mnuTop_" + num
   document.all(sName).onclick()
}
0
Comment
Question by:anderlecht
9 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7171537
obj.document.links[0].onclick()

CJ
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7171538
with 0 being the index of that link.

CJ
0
 

Author Comment

by:anderlecht
ID: 7173691
It seems that it is impossible to trigger programatically the onclick event in NS4 !
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 10

Expert Comment

by:zvonko
ID: 7173737
Does this event you try to fire by script react to real mouse clicks?

0
 

Author Comment

by:anderlecht
ID: 7173762
Yes, when i click on my link it works
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7173775
Check this script:

<html>
 <head>
 
 </head>
 
 <body>
  <a href="" onClick="alert('link 1 clicked');return false">Link 1</a>
  <a href="#" onClick="document.links[0].onclick();return false">Fire link 1</a>
 </body>
</html>
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 200 total points
ID: 7173785
or this script for when the link is in a div

<html>
 <head>
  <script language="javascript">
  <!--
   function clickit()
   {
             lObj = document.layers?document.layers["mydiv"].document.links[0]:document.all["link0"];
             if(lObj) lObj.onclick();
   }
  //-->
  </script>
 </head>

 <body>
  <a href="#" onClick="clickit();return false">Fire link 1 in div</a>

  <div id="mydiv" style="position:absolute;visibility:visible;top:200px;left:100px;">
   <a href="" onClick="alert('link 1 clicked');return false" id="link0">Link 1</a>
  </div>
 </body>
</html>
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8330316
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to CJ_S
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Expert Comment

by:modulo
ID: 8395869
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question