use tags <script> with if and else

html, javascript, jquery

Solution

For the first part. you can do this:

if (anything) {
    $('head').append('<script src="cordova-2.5.0.js"></script>')
        .append('<script src="js/jquery-1.7.2.min.js"></script>')
        .append('<script src="js/jquery.mobile-1.1.1.min.js"></script>')
        .append('<script src="js/jquery.xdomainajax.js"></script>')
        .append('<script src="js/xml2json.js"></script>')    
        .append('<script src="js/prefixfree.min.js"></script>')
} else {
    $('head').append('<script src="js/ZipPlugin.js"></script>')
        .append('<script src="js/jquery-ui.min.js"></script>')
        .append('<script src="js/jquery.ui.touch-punch.min.js"></script>')
}

To change the script tag, do this:

var key ="http://smartphone.thnt.vn/VietGames/GhepTranhTu/Web/"
$('script[src="js/prefixfree.min.js"]').attr('src', key + 'js/prefixfree.min.js');

Problem

I have some script tag like this: ``` <script src="cordova-2.5.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery.mobile-1.1.1.min.js"></script> <script src="js/jquery.xdomainajax.js"></script> <script src="js/xml2json.js"></script> <script src="js/ZipPlugin.js"></script> <script src="js/jquery-ui.min.js"></script> <script src="js/jquery.ui.touch-punch.min.js"></script> <script src="js/prefixfree.min.js"></script> ``` This is my app i wrote using phonegap for android but i want to use code in web. And i dont use all for web page. Have any way to do it like using if else like this in html: ``` if(anything) { <script src="cordova-2.5.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery.mobile-1.1.1.min.js"></script> <script src="js/jquery.xdomainajax.js"></script> <script src="js/xml2json.js"></script> <script src="js/prefixfree.min.js"></script> } else { <script src="js/ZipPlugin.js"></script> <script src="js/jquery-ui.min.js"></script> <script src="js/jquery.ui.touch-punch.min.js"></script> } ``` I am a dumper, please help me. Thanks for reading!!! Edit: if i want to change my script tag: ``` <script src="js/prefixfree.min.js"></script> ``` Become like this: ``` <script src="http://smartphone.thnt.vn/VietGames/GhepTranhTu/Web/js/prefixfree.min.js"></script> ``` Have anyway to make a variable like: ``` var key ="http://smartphone.thnt.vn/VietGames/GhepTranhTu/Web/" ``` And then use in tag like this: ``` <script src = "key + 'js/prefixfree.min.js'"></script> ```

Original source

Related problems