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)
CodePudding user response:
I am new to javascript too I found three mistakes in your code
- remove document no meaning to use it
- the semicolon missing in the function statement
- 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
CodePudding user response:
Please add return <input type="button" value="Click me please, it wont install a virus or a keylogger" onclick= return dothing() >
CodePudding user response:
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.
CodePudding user response:
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>