I want to include the jquery in file, if not included already in the page. How can I do this?
I wrote this, but it's giving undesired output.
<script type="text/javascript">
if ('undefined' == typeof window.jQuery) {
// jQuery not present
// alert("Jquery Unavailable");
<?php echo '<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>'; ?>
} else {
// jQuery present
alert("Jquery Available");
}
</script>
<script type="text/javascript">
if(typeof jQuery == 'undefined'){
var oScriptElem = document.createElement("script");
oScriptElem.type = "text/javascript";
oScriptElem.src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
document.head.insertBefore(oScriptElem, document.head.getElementsByTagName("script")[0])
}
</script>
You could try the below:
<script>window.jQuery || document.write('<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"><\/script>')</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With