1

Possible Duplicate:
How can I get the content of the file specified as the ‘src’ of a <script> tag?

I want to print my "definition" of script, preventing it will be executed.

Tried with :

var scriptWidget = document.createElement('script');
scriptWidget.type = 'text/javascript';
scriptWidget.src = "http://www.mywebsite.it/file.js";

$('#widget-html-codici').html(escape(scriptWidget));

but it prints %5Bobject%20HTMLScriptElement%5D. How can I print the code as "code"?

Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

1

What if you simply use the following:

var script = '<script type="text/javascript" '    // pay attention to
    + 'src="http://www.mywebsite.it/file.js"></'  // splitting of '</'
    + 'script>';                                  // and 'script>'

$('#widget-html-codici').text(script);​

DEMO: http://jsfiddle.net/NPBJm/

VisioN
  • 143,310
  • 32
  • 282
  • 281
1

You can do:

var scriptWidget = document.createElement('script');
scriptWidget.type = 'text/javascript';
scriptWidget.src = "http://www.mywebsite.it/file.js";

console.log(scriptWidget.outerHTML);

Demo on JSFiddle

Aamir
  • 5,324
  • 2
  • 30
  • 47
  • 1
    `alert` and `console.log` is not the same as pushing the value to the markup: http://jsfiddle.net/qebCy/1/. – VisioN Nov 20 '12 at 13:46