jquery - Read url and output new javascript src -
so on page load want following:
<script> $(document).ready(function () { if (document.location.hostname == "somemachine.poc") { var fileref = document.createelement('script') fileref.setattribute("type", "text/javascript") fileref.setattribute("src", "myscript.js") } }); </script>
in theory , practice correct? reason put on page , doesn't work expected, , doesn't show in source of page.
so end doing checking several domains, dependent on domain different src .js load.
update
the answers below helped me fix issue, have new issue follows on naturally question can found here: losing entire page dom running javascript
you have add script document.
document.body.appendchild(fileref);
it still won't show in source though. dom, modified js, not source. have use dom viewer see (e.g. chrome developer tools or opera dragonfly).
Comments
Post a Comment