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"?

4

2 に答える 2

1

単純に次を使用するとどうなりますか。

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);​

デモ: http://jsfiddle.net/NPBJm/

于 2012-11-20T13:39:53.447 に答える
1

できるよ:

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

console.log(scriptWidget.outerHTML);

JSFiddle のデモ

于 2012-11-20T13:41:11.447 に答える