Thompson Thompson - 2 years ago 151
Javascript Question

Include jQuery, if not included already

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=""></script>'; ?>
} else {
// jQuery present
alert("Jquery Available");

Answer Source

you cant do that in PHP. Try this instead

<script type="text/javascript">

if(typeof jQuery == 'undefined'){
        document.write('<script type="text/javascript" src=""></'+'script>');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download