0

I have code is this jsFiddle

I have it in a script called AutoPolicy.js at the same location, which I'm trying to call using a bookmarklet:

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

When I run this in chrome (not tried other browsers yet), I get an error:

Uncaught SyntaxError: Unexpected token ILLEGAL Sorry - I can't seem to find any more information on the error.

Waat is causing this error and why does it run on jsFiddle but not when called from the bookmarklet?

Thanks

Davy

davy
  • 4,474
  • 10
  • 48
  • 71

1 Answers1

0

I guess that it is the paren just after the createElement which is misplaced (attribute src is for the script element and not the document.body) :

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

EDIT

Edited code in order to separate the treatments:

javascript:(function(){var%20src='http://localhost:43911/Scripts/AutoPolicy.js',s=document.createElement('script');s.src=src;document.body.appendChild(s);})();
Samuel Caillerie
  • 8,259
  • 1
  • 27
  • 33