0

The code below seems valid to me; do I really have a syntax error? Running this code in a console:

$("body").append($("<script />", {
  html: "  window.fbAsyncInit = function() { "+
"    FB.init({"+
"      appId      : '[valid_id]', // App ID"+
"      status     : true, // check login status"+
"      cookie     : true, // enable cookies to allow the server to access the session"+
"      xfbml      : true  // parse XFBML"+
"    });"+
"  };"+
"  (function(d){"+
"     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];"+
"     if (d.getElementById(id)) {return;}"+
"     js = d.createElement('script'); js.id = id; js.async = true;"+
"     js.src = 'https://connect.facebook.net/en_US/all.js';"+
"     ref.parentNode.insertBefore(js, ref);"+
"   }(document));"
}));

Returns:

SyntaxError: Unexpected end of input

1 Answer 1

2

After looking at it for a while, it was quite obvious ;-)

All your concatenated string parts boil done to one line of JavaScript code eventually – so you can’t use // comments in there, because the go up to where? Exactly, the end of the line!

Either strip out the comments totally – or use the /* comment */ syntax.

Sign up to request clarification or add additional context in comments.

1 Comment

Finally, someone notices! :-) Oh, and forgot a third option: Putting a line break \n at the end of each string that contains a // comment should also work …

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.