next Posted August 1, 2008 Share Posted August 1, 2008 How can i click a link based on where it redirects you? For instance i want to loop through all links on a page and make a click only if text "Add=1" is a part of href. for(var i=0; i<=document.links.length; i++) if(document.links.search['Add=1']) alert(document.links[i].href); i tried this, but it's not working. Thanks. Link to comment https://forums.phpfreaks.com/topic/117733-click-a-link-based-on-its-href-attribute/ Share on other sites More sharing options...
next Posted August 1, 2008 Author Share Posted August 1, 2008 source snuppet: <a href="DocumentList.asp?wonum=PM-102545&bAdd=1"><img src="/AEOFM/Desk/images/Max5Style/btn_add.gif" border="0" /></a> Link to comment https://forums.phpfreaks.com/topic/117733-click-a-link-based-on-its-href-attribute/#findComment-605551 Share on other sites More sharing options...
KevinM1 Posted August 1, 2008 Share Posted August 1, 2008 <script type="text/javascript"> window.onload = function() { var links = document.getElementsByTagName('a'); var goodLinks = new Array(); for(var i = 0; i < links.length; i++) { if(links[i].href.slice(-5) === "add=1") { goodLinks.push(links[i]); } } //goodLinks is now an array with all <a> elements whose href attribute ends in add=1 } </script> Link to comment https://forums.phpfreaks.com/topic/117733-click-a-link-based-on-its-href-attribute/#findComment-605570 Share on other sites More sharing options...
next Posted August 1, 2008 Author Share Posted August 1, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/117733-click-a-link-based-on-its-href-attribute/#findComment-605656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.