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. Quote Link to comment 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> Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
next Posted August 1, 2008 Author Share Posted August 1, 2008 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.