运行脚本时出现书签错误



我有代码是这个jsFiddle

我把它放在一个名为 AutoPolicy 的脚本中.js在同一位置,我尝试使用书签调用它:

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

当我在chrome中运行它时(尚未尝试其他浏览器),出现错误:

未捕获的语法错误:意外令牌非法 抱歉 - 我似乎找不到有关该错误的更多信息。

Waat 导致此错误,为什么它在 jsFiddle 上运行,但在从书签调用时不运行?

谢谢

戴维

我猜是createElement后面的paren放错了地方(属性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);})();

最新更新