0

我有代码是这个jsFiddle

我在同一个位置的一个名为 AutoPolicy.js 的脚本中拥有它,我试图使用一个小书签来调用它:

javascript: (function(){document.body.appendChild(document.createElement('script')).src='http://localhost:43911/Scripts/AutoPolicy.js';})();

当我在 chrome 中运行它时(还没有尝试过其他浏览器),我收到一个错误:

Uncaught SyntaxError: Unexpected token ILLEGAL抱歉 - 我似乎找不到有关该错误的更多信息。

Waat 导致了这个错误,为什么它在 jsFiddle 上运行,但在从小书签调用时却没有?

谢谢

戴维

4

1 回答 1

0

我猜createElement这是放错位置之后的括号(属性src是脚本元素而不是document.body):

javascript: (function(){document.body.appendChild(document.createElement('script').src='http://localhost:43911/Scripts/AutoPolicy.js');})();

编辑

编辑代码以分离处理:

javascript:(function(){var%20src='http://localhost:43911/Scripts/AutoPolicy.js',s=document.createElement('script');s.src=src;document.body.appendChild(s);})();
于 2012-11-30T10:01:06.647 回答