cyfer65 Posted October 8, 2009 Share Posted October 8, 2009 I know how to Auto Click a link by its ID..But How can I Auto Click a link that doesn't have an ID..??Is there anyway to get the link by its .innerhtml LinkText "<a href="http://site.com">LinkTex</a>" var linkPage = document.getElementById('LinkTex').href;window.location.href = linkPage; Link to comment Share on other sites More sharing options...
Synook Posted October 8, 2009 Share Posted October 8, 2009 You'll have to loop through all links and check the innerHTML one by one: links = document.getElementsByTagName("a");for (var i = 0; i < links.length; i++) { if (links[i].innerHTML == "LinkTex") { window.location = links[i].getAttribute("href"); break; }} Note that setting the location to the link's href is not the same as clicking on it, e.g. the onclick handler isn't fired. Link to comment Share on other sites More sharing options...
cyfer65 Posted October 8, 2009 Author Share Posted October 8, 2009 is there anyway to make onclick handler get fired..?? Link to comment Share on other sites More sharing options...
Ingolme Posted October 8, 2009 Share Posted October 8, 2009 is there anyway to make onclick handler get fired..??It's not simple, but there's a procedure that uses dispatchEvent().http://www.howtocreate.co.uk/tutorials/javascript/domeventsThis is advanced Javascript, you should have a good knowledge of events and event handlers before trying this. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.