Solved

Chrome: click()

Posted on 2010-08-26
12
1,012 Views
Last Modified: 2013-12-07
Hi,

I have a site that works with IE.
Now I am trying to make it work with Chrome and FireFox.

I see that the element.click()  (in JavaScript)  doesn't work in chrome.
Is there another way to do it?


0
Comment
Question by:VapiSoft
  • 7
  • 5
12 Comments
 
LVL 4

Expert Comment

by:flexiwebsw
ID: 33536503
Ive just tried it in chrome, firefox, opera and ie and it works fine in all browsers, whats the piece of code that your using? maybe theres an error that chrome picks up.
0
 
LVL 4

Expert Comment

by:flexiwebsw
ID: 33536508
ive tried this axample and it works fine.
<input type="checkbox" onClick="document.getElementById('theSubmitButton').click();">Check the box to simulate a button click

<br>

<input type="button" name="theSubmitButton" id="theSubmitButton" value="Button" onClick="alert('The button was clicked.');">

Open in new window

0
 

Author Comment

by:VapiSoft
ID: 33536583
I think you misunderstood the question.

onclick event works fine.

the method element.click() that you can execute a click on an element (in JavaScript)  doesn't work.
0
 
LVL 4

Expert Comment

by:flexiwebsw
ID: 33536786
yes i completely understood your question, in the example i posted if you click on the checkbox then it simulates a click on the button which runs the alert coded on the button onclick parameter.
0
 

Author Comment

by:VapiSoft
ID: 33537032
You are right.
It does work when I click on a button (as in your example).
But it doesn't work when I click on the expand (+) icon in a 'tree-table'.

+ ...
+....
I added an alert before the click and after the click.
It shows only the first alert.
0
 
LVL 4

Expert Comment

by:flexiwebsw
ID: 33537071
if you post your source code for that area, i will have a look and fix it for you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:VapiSoft
ID: 33537251
the site is:
http://www.vapisoft.com/MyTree/main.php

click on the 'Comments' at the bottom.
Then click on 'Maximize'.
The click on 'Open All' (at the top).
It works in IE but not in Chrome.
It activates the attached function.

function openAll(checked,table)

{

 var do_again=true;

 var name="minus";

 if (checked) name="plus";

 

 while (do_again)

 {

  do_again=false;

  var allPageTags=document.getElementsByTagName("*");

  for (var i=0; i<allPageTags.length; i++) 

  {  

   if (allPageTags[i].className== 'expandimg') 

   { 

    var src=allPageTags[i].src;

    if (src.indexOf(name) > 0)

    {

     if (allPageTags[i].id.match('^'+table))

     {

	  var obj=allPageTags[i];

	  obj.click();

	  do_again=true;

     }

    }

   }

  } 

 }

}

Open in new window

0
 
LVL 4

Expert Comment

by:flexiwebsw
ID: 33537506
you get the error

'allPageTags[i].click is not a function'

othher browsers dont detect the image.clicl(); as a function
0
 
LVL 4

Accepted Solution

by:
flexiwebsw earned 500 total points
ID: 33537570
i think other browsers dont like the fact thats its an image, it thinks you cant click it.
0
 

Author Comment

by:VapiSoft
ID: 33537813
so what can I do?
0
 

Author Closing Comment

by:VapiSoft
ID: 33537841
I don't have a solution, but thanks for the help.
0
 
LVL 4

Expert Comment

by:flexiwebsw
ID: 33537866
try this, it works fine

you willl have to replace your image with an input tag, but set the type to image, it works fine in all browsers.
<input type="checkbox" onClick="document.getElementById('theSubmitButton').click();">Check the box to simulate a button click

<br>

<input type="image" src="http://www.vlerickalumni.com/images/icons/plusIcon.gif" name="theSubmitButton" id="theSubmitButton" onClick="alert('The button was clicked.'); return false;">

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript/Java - Changing an image background color 4 54
Basic JavaScript Question 3 37
Animated .jpg? 13 55
Chrome SSRS print Functionality 1 17
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Several part series to implement Internet Explorer 11 Enterprise Mode
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

943 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

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now