Get data attribute of script tag?

For modern browsers that support html5 you can use document.currentScript to get the current script element. Otherwise, use querySelector() to select your script element by id or attribute. Note that we don’t use the src attribute because that can be fragile if you’re delivering over a CDN or with differences between development and production environments. … Read more

“Unterminated template literal” syntax error when literal contains script tag [duplicate]

If you insert </script> inside a script tag, no matter if it’s a string in quotes, apostrophes, or even a template literal, it will always close the script tag. You have to escape it, for example like that: var str=` <script> <\/script> ` var pre = document.createElement(‘pre’) pre.textContent = str document.body.appendChild(pre) However, if you use … Read more

How to force a script reload and re-execute?

How about adding a new script tag to <head> with the script to (re)load? Something like below: <script> function load_js() { var head= document.getElementsByTagName(‘head’)[0]; var script= document.createElement(‘script’); script.src=”https://stackoverflow.com/questions/9642205/source_file.js”; head.appendChild(script); } load_js(); </script> The main point is inserting a new script tag — you can remove the old one without consequence. You may need to add … Read more

HTML/Javascript: how to access JSON data loaded in a script tag with src set

You can’t load JSON like that, sorry. I know you’re thinking “why I can’t I just use src here? I’ve seen stuff like this…”: <script id=”myJson” type=”application/json”> { name: ‘Foo’ } </script> <script type=”text/javascript”> $(function() { var x = JSON.parse($(‘#myJson’).html()); alert(x.name); //Foo }); </script> … well to put it simply, that was just the script … Read more

How to pass parameters to a Script tag?

I apologise for replying to a super old question but after spending an hour wrestling with the above solutions I opted for simpler stuff. <script src=”..” one=”1″ two=”2″></script> Inside above script: document.currentScript.getAttribute(‘one’); // 1 document.currentScript.getAttribute(‘two’); // 2 Much easier than jQuery or URL parsing. You might need the polyfill for document.currentScript from @Yared Rodriguez’s answer … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)