script-tag

Why call $.getScript instead of using the <script> tag directly?

北战南征 提交于 2019-11-29 14:05:00
I don't understand the reason for replacing this: <script src="js/example.js"></script> with this: $.getScript('js/example.js', function() { alert('Load was performed.'); }); Is there a particular reason to use the jQuery version? The only reason I can think of is that you get the callback when the script is loaded. But you can get that callback using a script tag, too, by using the load event (or on really old IE, onreadystatechange ). In contrast, there are several negatives to doing it this way, not least that getScript is subject to the Same Origin Policy , whereas a script tag is not.

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

*爱你&永不变心* 提交于 2019-11-29 11:00:03
问题 This question already has answers here : Why split the <script> tag when writing it with document.write()? (5 answers) Closed 2 years ago . I'm using ES6 template literals to construct some HTML in strings, and so far it has been working fine. However, as soon as I try to put the literal text </script> in my string the browser throws up and throws the syntax error: SyntaxError: Unterminated template literal Here is a simple JavaScript sample which throws the error: var str=` <script> </script

Remove <script> tags using jQuery

廉价感情. 提交于 2019-11-29 09:23:11
I want to remove this Google Analytics block, using jQuery. <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { //var pageTracker = _gat._getTracker("xxx"); pageTracker._trackPageview(); } catch(err) {} </script> THE REASON Because I am creating a bespoke screen reader convertor for jQuery based on a client specification. It's the Google Analytics

<script> tag inside jquery template

两盒软妹~` 提交于 2019-11-29 09:07:30
Backgroud: I have this template that includes videos from youtube being loaded with swfobject. Question: Is there a way to include a script tag... <script type="text/javascript"> </script> inside a jQuery Template?? <script id="filaVideoTemplate" type="text/x-jQuery-tmpl"> <!-- Some HTML here --> <script type="text/javascript"> <!-- Some javascript here --> </script> </script> Obviously it doesn't work directly, is there any way to achive the same thing without the script inside other script? <script id="filaVideoTemplate" type="text/x-jQuery-tmpl"> <!-- Some HTML here --> <script type="text

When should <script> tags be visible and why can they?

蹲街弑〆低调 提交于 2019-11-28 16:26:28
A script element that got styled as display:block appears visible. Why is it possible and is there any real use case where it is desired? td > * { display: block; } <table> <tr> <td> <script type="text/javascript"> var test = 1; </script>von 1 </td> </tr> </table> unor The HTML5 specification defines a style sheet that user agents (like browsers) are expected to use. Section 10.3.1 lists the styles for "Hidden elements": @namespace url(http://www.w3.org/1999/xhtml); [hidden], area, base, basefont, datalist, head, link, meta, noembed, noframes, param, rp, script, source, style, template, track,

Why call $.getScript instead of using the <script> tag directly?

ぃ、小莉子 提交于 2019-11-28 07:41:26
问题 I don't understand the reason for replacing this: <script src="js/example.js"></script> with this: $.getScript('js/example.js', function() { alert('Load was performed.'); }); Is there a particular reason to use the jQuery version? 回答1: The only reason I can think of is that you get the callback when the script is loaded. But you can get that callback using a script tag, too, by using the load event (or on really old IE, onreadystatechange ). In contrast, there are several negatives to doing

multiple versus single script tags

眉间皱痕 提交于 2019-11-28 04:29:23
Is there any difference (performance, best practices, etc) between using a single script tag with embedded code in it, or using multiple script tags with the same code spread all over the HTML? For example: <script> foo(); </script> ... <script> bar(); </script> versus: <script> foo(); bar(); </script> Thanks With inline script like what you quoted, there's unlikely to be much difference; however, every time the browser's HTML parser encounters a script tag, it: Comes to a screeching halt Builds up a string of the the text in the tag up until the first time it sees the string "</script>" Hands

Remove <script> tags using jQuery

一笑奈何 提交于 2019-11-28 02:45:14
问题 I want to remove this Google Analytics block, using jQuery. <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { //var pageTracker = _gat._getTracker("xxx"); pageTracker._trackPageview(); } catch(err) {} </script> THE REASON Because I am creating a

<script> tag inside jquery template

时光毁灭记忆、已成空白 提交于 2019-11-28 02:28:57
问题 Backgroud: I have this template that includes videos from youtube being loaded with swfobject. Question: Is there a way to include a script tag... <script type="text/javascript"> </script> inside a jQuery Template?? <script id="filaVideoTemplate" type="text/x-jQuery-tmpl"> <!-- Some HTML here --> <script type="text/javascript"> <!-- Some javascript here --> </script> </script> Obviously it doesn't work directly, is there any way to achive the same thing without the script inside other script?

How does HTML tags work inside script tag?

南楼画角 提交于 2019-11-27 18:32:42
For example, view-source at Joel Spolsky's public career profile <script type="text/html" id="stackexchangeanswerswidget"> <h3>Top Answers</h3> <div class="answers"> </div> </script> <script type="text/html" id="topanswer"> <div class="top-answer"> <div class="top-answer-stats">{{= shared.htmlEncode(Score) }}</div> <span class="top-answer-title"><a href="{{=AnswerLink}}">{{= shared.htmlEncode(Title) }}</a></span> <a class="add-answer">add</a> <br class="clear" /> </div> </script> <script type="text/html" id="answer-view"> <div class="answer"> <div class="answer-stats {{= shared.htmlEncode(Site