简体   繁体   中英

Same name for a string and a function

Right now I'm having a major brain fart. I have this function:

function uplodeVirus(){
  console.log('working')
  console.log('uplodeVirus')
  var form = document.getElementsByTagName('form')[1]
  console.log(form)
  var select = form.children[0]
  console.log(select)
  for (x in select) {
    var lN = select[x].innerHTML // var linkName
    if (lN == "vspam 0.3 [OpenRelay-backdoor.vspam ] (0.003 Gb)"){
      value = select[x].value
      select[x].setAttribute("selected", "selected");
      form.submit()
      break
    }  
  }
}

Don't worry its not a real Virus!!! This is a bot for a game called slave hack - for learning purposes

Anyways, when I call the function:

var ip = '2.2.2.2'
var uplodeVirus = 'http://www.slavehack.com/index2.php?page=internet&var2=' + ip + '&var3=files&aktie=upload'
var currentUrl = window.location.href
console.log(currentUrl)
console.log(uplodeVirus)
if (currentUrl == uplodeVirus) { //Yes, I made sure that currentUrl = uplodeVirus
  uplodeVirus()
}

Nothing happens... but if I take the code out of the function and do this:

if (currentUrl == uplodeVirus){ 
  console.log('working')
  console.log('uplodeVirus')
  var form = document.getElementsByTagName('form')[1]
  console.log(form)
  var select = form.children[0]
  console.log(select)
  for (x in select) {
    var lN = select[x].innerHTML // var linkName
    if (lN == "vspam 0.3 [OpenRelay-backdoor.vspam ] (0.003 Gb)"){
      value = select[x].value
      select[x].setAttribute("selected", "selected");
      form.submit()
      break
    }  
  }
}

It works!!! Now, I could go with option B, but I really want to figure out what i did wrong.

Thanks in advance!

You are naming both a URL variable and a function with the same name: uplodeVirus

Since the variable is initialized to hold a string before you try to call the function, calling uplodeVirus() is the same as calling ("")() . It doesn't make any sense, because a string is not a function.

Try changing the name of one or the other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM