{"id":6704,"date":"2014-04-22T04:37:37","date_gmt":"2014-04-22T04:37:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/22\/auto-include-javascript-file-if-not-already-included-collection-of-common-programming-errors-2\/"},"modified":"2014-04-22T04:37:37","modified_gmt":"2014-04-22T04:37:37","slug":"auto-include-javascript-file-if-not-already-included-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/22\/auto-include-javascript-file-if-not-already-included-collection-of-common-programming-errors-2\/","title":{"rendered":"Auto include javascript file if not already included-Collection of common programming errors"},"content":{"rendered":"<p>Well if that JavaScript file defines a specific variable (or a function) you can check its presence by checking <code>typeof that_variable<\/code>, then load the JavaScript file if necessary. An example, here is how you load swfobject library if its not available on the page:<\/p>\n<pre><code>if (typeof swfobject == \"undefined\") {\n   var e = document.createElement(\"script\");\n   e.src = \"http:\/\/ajax.googleapis.com\/ajax\/libs\/swfobject\/2\/swfobject.js\";\n   e.type = \"text\/javascript\";\n   document.getElementsByTagName(\"head\")[0].appendChild(e); \n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Well if that JavaScript file defines a specific variable (or a function) you can check its presence by checking typeof that_variable, then load the JavaScript file if necessary. An example, here is how you load swfobject library if its not available on the page: if (typeof swfobject == &#8220;undefined&#8221;) { var e = document.createElement(&#8220;script&#8221;); e.src [&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-6704","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6704","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=6704"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6704\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}