コード:
p_initJQuery();
function p_initJQuery() {
if (typeof jQuery === "undefined") {
var script_tag = document.createElement('script');
script_tag.setAttribute("type", "text/javascript");
script_tag.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js")
script_tag.onload = punctis_load_box;
script_tag.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') punctis_load_box();
}
document.getElementsByTagName("head")[0].appendChild(script_tag);
} else {
punctis_load_box();
}
}
function punctis_load_box() {
$(".punctis-social-box").html(typeof jQuery);
}
このコードは、ロードされていない場合は何も知らないページに挿入されることを意図しているため、サイトを制御している私はまだjqueryをロードしていません。これは私のテスト サイトでは正常に動作していますが、別のより複雑なサイトで試してみると、 Uncaught TypeError: Property '$' of object [object Window] is not a functionで失敗します。
何が起こっているのかわかりません。