-3

I presume that inline JavaScript bound to orerror, onclick, ... run.

But would a <script type="text/javascript">...</script> element run javascript as well when wrapped with $(...) ?


If it does run is it sand-boxed?


Sorry for the misunderstanding:

Wanted to make sure that JavaScript loaded within the $ method would NOT run. I'm aware of other methods on how to load JavaScript scripts within the page and I generally use require.

Just wanted to figure out how much of a security risk wrapping HTML (containing script tags) within $ could be.

If someone can give me some insight/directions on how JavaScript is interpreted within the jQuery method that would give me my answer thanks.


Thanks :)

2
  • It's difficult to tell whats being asked here, what do you mean by "<script type="text/javascript">...</script> element run JS"? Jan 25, 2013 at 10:54
  • I want to avoid JavaScript scripts from being executed when wrapped in $.
    – RadiantHex
    Jan 25, 2013 at 10:58

2 Answers 2

0

You always need to write

<script type="text/javascript"></script> 
or 
if you use the html5 Doctype
<script></script> 

when you want to execute Javascript. in your html files.

If you want to execute javascript without writing these tags then you need to add a extern .js file and link to that file like this:

<script src="pathtofile/javascript.js"></script>
1
  • I want to avoid JavaScript running within jQuery
    – RadiantHex
    Jan 25, 2013 at 10:57
0

Friend please excuse me if my understanding of the question was wrong.

if you wrap some code in $() it will consider it as either the javascript or jquery code. But as we know script is a tag not a javascript code, so finally it will be throwing an error.

In order to execute any code which is in script tag, please place the code in a file and use getScript() function of jquery by enclosing in $(). Finally your requirement might be met :).

$(function() {
    $.getScript(pathoffile);
}); 
1
  • Right, I meant to say $(<script></script>) will be throwing error :) Jan 26, 2013 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.