Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Maybe a simple fix?

    Hi,

    Im trying to make an imacro/javascript script that checks a webpage for names, and if either of the names are found, i want the script to alert me, if not, continue looping/reloading the page.

    Im not at all good with javascript, imacro is more sort of my thing, however what i do have, doesnt seem to do anything.

    var links = document.getElementsByTagName('a');
    for (var i in links){
    if (links[i].value == "Simon" || links[i].value == "James"){
    alert("ATTENTION");
    }
    }


    i dont know if its something simple i'm missing, or whether im nowhere near, but ive spent all day trying to do this, and lost all patience.

    Any suggestion/fixes?

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Here is something to consider ...

    Code:
    <body>
    <a href=# >johnny</a>
    <a href=# >ralph</a>
    <a href=# >sue</a>
    <a href=# >James</a>
    </body>
    <script>
    var links = document.getElementsByTagName('a');
    for (var i = links.length;i--;){
    	if (links[i].innerHTML == "Simon" || links[i].innerHTML == "James"){
    		alert("ATTENTION");
    	}
    }
    </script>

  • #3
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    [ot]

    I doubt putting javascript outside of the <body> element is valid. It should be in the <head> or <body>

    [/ot]

  • #4
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Meh, it doesnt work. And clearly i dont know what im doing.

    WebDev, im using the javascript in iMacros firefox plugin, which doesnt need any body etc.

    Infact, using the first code Davey gave me, it errored and wouldnt run because of ''SyntaxError: invalid XML attribute value (Error code: 991)''



    I dont know what else to try.

  • #5
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And thank you both for the speedy replies.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •