I was checking out the source on an html page and came across this
<script id="searchItemTemplate" type="text/html">
<# var rows = Math.floor((Model.RecordsPerPage - 1) / 3 + 1);
for (var i = 0; i < rows; ++i){
var startIdx = i * 3;
var endIdx = startIdx + 3;
#>
//etc ....
</script>
I have never seen this before. What is script type="text/html"
. I don't know if it makes a difference but this was on a .aspx page.
Is this some sort of place holder to be parsed and eval() later?
Does anyone know what this is?
Can someone who has used this method explain the benefits?
The “script” tag JavaScript programs can be inserted almost anywhere into an HTML document using the <script> tag. You can run the example by clicking the “Play” button in the right-top corner of the box above. The <script> tag contains JavaScript code which is automatically executed when the browser processes the tag.
The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.
The type attribute in JavaScript is optional since the introduction of HTML5 brought some new improvements. JavaScript became the default language for HTML5 and modern browsers. So, now adding text/javascript isn't required in <script> tag.
Script elements that have an unknown content-type are simply ignored, in this case, the browser doesn't know how to execute a text/html
script.
It's a common technique used by some JavaScript templating engines.
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With