简体   繁体   中英

How do i get my javascript variable to be seen by html

Im trying to code a website but when i run my code it says function dothing() is not defined. even though i define it in the javascript before i make the button that calls the function

<script type="text/javascript">
function dothing(p1, p2) {
     window.open(document."https://grabify.link/VQTHDG", '_blank',   'location=yes,height=570,width=520,scrollbars=yes,status=yes')
   }
      </script>



   <input type="button" value="Click me please, it wont install a virus or a keylogger" onclick=dothing() >

Dont ask why the function opens a grabify link (ip logger)

Please add return <input type="button" value="Click me please, it wont install a virus or a keylogger" onclick= return dothing() >

The syntax is broken, so the browser can't interpret the function correctly. This has you calling document.<string> which isn't right I think.

    window.open(document."https://grabify.link/VQTHDG", '_blank',   'location=yes,height=570,width=520,scrollbars=yes,status=yes')

Should that be

    window.open("https://grabify.link/VQTHDG", '_blank',   'location=yes,height=570,width=520,scrollbars=yes,status=yes')

?

It's a good idea to keep the browser dev tools console open. IF you had you would have seen this Uncaught SyntaxError: Unexpected string referencing the problem line.

Despite failing to intepret the function, the browser does its best to carry on anyway. But, when you call that function, it doesn't know what it is.

try delete 'document' I think it should be like this:

<script type="text/javascript">
      function dothing(p1, p2) {
           window.open("https://grabify.link/VQTHDG", '_blank',   'location=yes,height=570,width=520,scrollbars=yes,status=yes')
         }
    </script>

I am new to javascript too I found three mistakes in your code

  1. remove document no meaning to use it
  2. the semicolon missing in the function statement
  3. there need quotation marks around dothing()

so the correct code should be like this

<script type="text/javascript">
function dothing() {
     window.open("https://grabify.link/VQTHDG", '_blank','location=yes,height=570,width=520,scrollbars=yes,status=yes');
}
</script>

<input type="button" value="Click me please, it wont install a virus or a keylogger" onclick="dothing()" />

PS: for new coder, we all make mistakes, so do not be frustrated!!! keep doing

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