Javascript in javascript IF condtion
NickName:Anurag Ask DateTime:2015-02-03T06:07:32

Javascript in javascript IF condtion

How can I call another javascript in a condition. Lets say I have

    <script type="text/javascript">
if(condition)
{
< script type="text/javascript" src="">< /script>}
else(condition)
{
< script type="text/javascript" src="">< /script>}

Copyright Notice:Content Author:「Anurag」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28287703/javascript-in-javascript-if-condtion

Answers
user4058999 2015-02-02T22:14:00

How about:\n\n <script type=\"text/javascript\">\n var head = document.getElementsByTagName(\"head\")[0];\n var script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n if(condition) {\n script.src = \"one.js\";\n } else {\n script.src = \"two.js\";\n } \n head.appendChild(script);\n </script>\n",


w3bMak3r 2015-02-02T22:14:32

How about place something like this in your head:\n\n<script>\n if(someCondition){\n document.write(\\'<script src=\"awesome-script-a.js\"><\\/script>\\');\n }\n else{\n document.write(\\'<script src=\"awesome-script-b.js\"><\\/script>\\');\n }\n\n\n</script>\n\n\nThis is how HTML5 Broiler plate and The Roots.io Starter theme handles scripts loaded via CDN.\n\nThere is a slight performance hit as document.write writes to an already open page. \n\nSee http://javascript.info/tutorial/document-write",


Rinrub 2015-02-02T22:10:26

getscript method in jquery lest you Get a script inside your JavaScript code",


camilaazuma 2017-10-05T21:47:02

Try something like:\n\n<script type=\"text/javascript\">\n var script = document.createElement('script');\n script.type = 'text/javascript';\n script.src = true ? 'source1' : 'source2';\n document.querySelector('head').appendChild(script);\n</script>\n",


More about “Javascript in javascript IF condtion” related questions

Javascript in javascript IF condtion

How can I call another javascript in a condition. Lets say I have &lt;script type="text/javascript"&gt; if(condition) { &lt; script type="text/javascript" src=""&gt;&lt; /s

Show Detail

jquery Instafeed if functon exist or condtion exist

Instagram jquery script. A simple Instagram javascript plugin http://instafeedjs.com Iam use ing instafeed code: site basic use instrgram condions https://github.com/johndeng/instafeed.js jQuery(

Show Detail

ie 8 show itself as ie7 [CSS if condtion]?

ie8 version on my computer , show itself as ie 7 when i use CSS IE CONDTION like &lt;!--[if IE 7]&gt; &lt;script type="text/javascript"&gt;alert('hello iam ie 7 :P ');&lt;/script&gt; &lt;!

Show Detail

Sequelize OR Condtion

I want to do, Where Student Name Or Email &quot;SELECT * FROM Student WHERE Name='Doe' OR Email='[email protected]' &quot; couldn't make OR condtion in Sequelize.

Show Detail

ngx-translate in terinory condtion in angular 8

here the issue is ngx translate in ternary condtion . {{ (videoConfig === true) ? 'Disable Video' : 'Enable Video' }} i want to translate the word disable video and enable video in that condt...

Show Detail

Relation to Mutliple Table with condtion

i have 3 tables 1.Testcase : id 2.sceanrio : id, testcaseId 3.test case step: id testcase id,sceanrio id I m trying to make relationship for these table based on following condtion if test c...

Show Detail

run javascript function only if php conditions are met

I want the start_uploading function only to start if all the conditions are met and the file is uploading, right now the 'loading' message pops up for a split second when the form is submitted but ...

Show Detail

Validate image Resolution in Javascript, PHP

I want to validate Image Resolution before upload an image in PHP through Javascript. In my php form , i want to upload two different images and both image have different resolution restriction. ...

Show Detail

Javascript object proccesing confusion

I am at freecodecamp.com and stuck at a problem of Profile Lookup.What I am missing here? can anyone point me out ? If I comment out this condtion firstName == contacts[i].firstName it is returning 4

Show Detail

Onclick delegate with OR condtion JQuery

I have a refresh button on which I if I press the button there should be ajax call. if (($('#smart_sheet_area').is(':empty')) || ($(&quot;.page-content&quot;).delegate(&quot;.refresh-smartsheet&quo...

Show Detail