{"id":1748,"date":"2022-08-30T15:19:07","date_gmt":"2022-08-30T15:19:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/30\/facebook-javascript-sdk-not-working-on-xhtml-page-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:19:07","modified_gmt":"2022-08-30T15:19:07","slug":"facebook-javascript-sdk-not-working-on-xhtml-page-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/facebook-javascript-sdk-not-working-on-xhtml-page-collection-of-common-programming-errors\/","title":{"rendered":"Facebook Javascript SDK not working on .xhtml page-Collection of common programming errors"},"content":{"rendered":"<p>I tried out the Javascript SDK in an <code>html<\/code> file, everything worked fine. Then moved the same code to a <code>.xhtml<\/code> file &amp; it completely stopped working.<\/p>\n<p>The code as follows:<\/p>\n<p>Moved from file <code>test.html<\/code> to file <code>test.xhtml<\/code> &amp; it stopped working<\/p>\n<pre><code>\n    \n        \n    \n    \n        \n        \n            \/\/ Load the SDK Asynchronously\n            (function(d){\n                var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];\n                if (d.getElementById(id)) {return;}\n                js = d.createElement('script'); js.id = id; js.async = true;\n                js.src = \"\/\/connect.facebook.net\/en_US\/all.js\";\n                ref.parentNode.insertBefore(js, ref);\n            }(document));\n\n            \/\/ Init the SDK upon load\n            window.fbAsyncInit = function() {\n                FB.init({\n                    appId      : '365436556863538', \/\/ App ID\n                    channelUrl : '\/\/'+window.location.hostname+'\/channel', \/\/ Path to your Channel File\n                    status     : true, \/\/ check login status\n                    cookie     : true, \/\/ enable cookies to allow the server to access the session\n                    xfbml      : true  \/\/ parse XFBML\n                });\n\n                \/\/ listen for and handle auth.statusChange events\n                FB.Event.subscribe('auth.statusChange', function(response) {\n                    if (response.authResponse) { \n                        FB.api('\/me', function(response){\n                            if (response.name) {\n                                $(\"#username\").html(\"<img src='https:\/\/graph.facebook.com\/\"%20+%20response.id%20+%20\"\/picture' \/>\" + response.name  +\"\");\n\n                            }\n                        })\n                        $('#auth-loggedout').hide();\n                        $('#auth-loggedin').show();\n                    } else {\n                        \/\/ user has not auth'd your app, or is not logged into Facebook\n                        $('#auth-loggedout').show();\n                        $('#auth-loggedin').hide();\n                    }\n                });\n\n                \/\/ respond to clicks on the login and logout links\n                document.getElementById('auth-loginlink').addEventListener('click', function(){\n                    FB.login(function(response) {\n                       \/\/ handle the response\n                     }, {scope: 'email'});\n                });\n                document.getElementById('auth-logoutlink').addEventListener('click', function(){\n                    FB.logout();\n                }); \n            } \n        \n        \n            \n                Login\n            \n            \n                (logout)\n\n            \n        \n        \n            \n         \n    \n\n<\/code><\/pre>\n<p>I could just find this in the console window:<\/p>\n<blockquote>\n<p>Uncaught SyntaxError: Unexpected identifier<\/p>\n<p>window.script1342849602887=1;<\/p>\n<\/blockquote>\n<p id=\"rop\"><small>Originally posted 2013-11-30 19:06:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I tried out the Javascript SDK in an html file, everything worked fine. Then moved the same code to a .xhtml file &amp; it completely stopped working. The code as follows: Moved from file test.html to file test.xhtml &amp; it stopped working \/\/ Load the SDK Asynchronously (function(d){ var js, id = &#8216;facebook-jssdk&#8217;, ref = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1748","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1748"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1748\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}