javascript - change src from script which depend on the browser size -
i got little bit problem website
i'm trying change src attribute script based on browser size script inside of div
here how code looks like
<div style="margin: 15px 0px 0px; display: inline-block; text-align: center;"> <script id="world" type="text/javascript" src="http://localtimes.info/world_clock2.php?&cp1_hex=ffd700&cp2_hex=000000&cp3_hex=000000&fwdt=72&ham=0&hbg=0&hfg=0&sid=0&mon=0&wek=0&wkf=0&sep=0&widget_number=21000&lcid=snxx0006,usny0996,ukxx0085,asxx0112,hkxx0001"></script> </div> i'm trying change src script src contain width (fwdt value in script) of widget want change based on browser size
i'm trying solve problem following code
<script> var w = window.innerwidth; if (w>991) { document.getelementbyid("demo").innerhtml = "width: " + w ; $('#world').attr('src','http://localtimes.info/world_clock2.php?&cp1_hex=ffd700&cp2_hex=000000&cp3_hex=000000&fwdt=200&ham=0&hbg=0&hfg=0&sid=0&mon=0&wek=0&wkf=0&sep=0&widget_number=21000&lcid=snxx0006,usny0996,ukxx0085,asxx0112,hkxx0001'); } else if (w<991) { document.getelementbyid("demo").innerhtml = "width: " + w ; $('#world').attr('src','http://localtimes.info/world_clock2.php?&cp1_hex=ffd700&cp2_hex=000000&cp3_hex=000000&fwdt=100&ham=0&hbg=0&hfg=0&sid=0&mon=0&wek=0&wkf=0&sep=0&widget_number=21000&lcid=snxx0006,usny0996,ukxx0085,asxx0112,hkxx0001'); }; </script> however, code not script src
what found internet create script itself, using appendchild...but, appendchild work using tag name, in case script child div...
is there way solve it?
new
<script> var w = window.innerwidth; if (w>991) { document.getelementbyid("demo").innerhtml = "width " + w; $('#asd').append('<script type=\"text\/javascript\" src=\"http:\/\/localtimes.info\/world_clock2.php?&cp1_hex=ffd700&cp2_hex=000000&cp3_hex=000000&fwdt=100&ham=0&hbg=0&hfg=0&sid=0&mon=0&wek=0&wkf=0&sep=0&widget_number=21000&lcid=snxx0006,usny0996,ukxx0085,asxx0112,hkxx0001\"><\/script>'); } else if (w<991) { document.getelementbyid("demo").innerhtml = "width " + w; $('#asd').append('<script type=\"text\/javascript\" src=\"http:\/\/localtimes.info\/world_clock2.php?&cp1_hex=ffd700&cp2_hex=000000&cp3_hex=000000&fwdt=200&ham=0&hbg=0&hfg=0&sid=0&mon=0&wek=0&wkf=0&sep=0&widget_number=21000&lcid=snxx0006,usny0996,ukxx0085,asxx0112,hkxx0001\"><\/script>'); }; </script> i try use above code, not work too
it shows width number, append function not anything
"asd" id of div
is there other solustion?
setting src attribute of script tag can done once. have append new script tag programatically.
see answer changing "src" attribute of <script>
Comments
Post a Comment