If you already have jQuery added to your board, than you can skip this step.
as far I know there is no real way to detect if jquery exists.VSE wrote:I wonder, are there any: If jQuery already exists logic functions we could employ?
Code: Select all
<script type="text/javascript">
if (typeof $ != 'function')
alert("jquery don't exists");
else
alert("jquery exists");
</script>
Code: Select all
<script type="text/javascript">
if (typeof jQuery == 'undefined')
document.write('<script type="text/javascript" src="{T_TEMPLATE_PATH}/jquery.js" charset="utf-8"><\/script>');
</script>
Code: Select all
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
var script = document.createElement('script');
script.setAttribute("type","text/javascript");
script.setAttribute("src","{T_TEMPLATE_PATH}/jquery.js");
script.setAttribute("charset","utf-8");
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
I used the method appendChild. In the following code I am using the method insertBefore.VSE wrote:It seems only problem with that code, is it gets added right before the closing HEAD tag.
jQuery needs to be called before any other scripts that may use it, so is there a way to append it right after the opening HEAD tag instead??
<head>
tag in the template overall_header.html:<meta http-equiv="content-type" content="text/html; charset={S_CONTENT_ENCODING}" />
meta
element in pagevar meta = document.getElementsByTagName('meta')[0];
document.getElementsByTagName('head')[0].insertBefore(script,meta);
Code: Select all
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
var meta = document.getElementsByTagName('meta')[0];
var script = document.createElement('script');
script.setAttribute("type","text/javascript");
script.setAttribute("src","{T_TEMPLATE_PATH}/jquery.js");
script.setAttribute("charset","utf-8");
document.getElementsByTagName('head')[0].insertBefore(script,meta);
}
</script>
Code: Select all
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
var script = document.createElement('script');
script.setAttribute("type","text/javascript");
script.setAttribute("src","{T_TEMPLATE_PATH}/jquery.js");
script.setAttribute("charset","utf-8");
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
<script type="text/javascript" src="{T_TEMPLATE_PATH}/myscript.js" charset="utf-8"></script>