0

I can't figure out how to fix this. It says the onclick is missing a semi-colon. I'm sure I'm missing something obvious - any ideas?

<a href="http://mywebsite.com" onclick="setTimeout(location.href='https://www.facebook.com/myprofile', 10);return true;">
3
  • 5
    Trying to squeeze that much code into an onclick, or arguably even using onclick at all, is your first problem. Move it to the pages script file. Commented Sep 29, 2016 at 20:43
  • 2
    setTimeout expects to be passed a function. You are passing a string ("https://www.facebook.com/myprofile"), which gets evald as JavaScript code, but that string doesn't contain JavaScript, so an error is thrown. Commented Sep 29, 2016 at 20:44
  • Expanding on @LukePark 's comment about onclick - agree, avoid using onclick= and instead learn how to attach event handlers by using addEventListener or with a toolkit such as jQuery. Commented Sep 29, 2016 at 20:51

1 Answer 1

2

Your setTimeout syntax is invalid, it should be:

setTimeout(function() { location.href='https://www.facebook.com/myprofile'; }, 10);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.