i am trying to create a google gadget which should be built on javascript.every google gadget create a iframe element.due to some constraints i can't add jquery directly from script tag.i have to include it using javascript so i write a code
function addScript(jsRelativeUrl) {
var rebasedUrl = rebaseRelativeUrl(jsRelativeUrl,true);
var x = document.createElement('script');
x.type='"text/javascript"';
x.src='"'+rebasedUrl+'"';
if(x.src.indexOf('scripts/jquery-1.9.1.min.js')>=0)
document.head.appendChild(x)
else document.body.appendChild(x);
}
i am first calling this function
gadgets.util.registerOnLoadHandler(function(){
addScript('scripts/jquery-1.9.1.min.js');
$(function (){});
});
but it is giving me error
Uncaught ReferenceError: $ is not defined
and when i see in elements jQuery is included in head tag of iframe . can any one please help why i am getting this error and how to getrid of this ??
You are appending the
script
tag to load jquery at the end of either thehead
or thebody
of the embedding document. if the code you are executing is situated before the location of the jquery import tag (eg. in ascript
section of thehead
or - if appended to the end of thebody
- in ascript
section within thebody
), it cannot be present.