How to include JavaScript file or library in Chrome console?

technocake picture technocake · Mar 12, 2011 · Viewed 171.3k times · Source

Is there a simpler (native perhaps?) way to include an external script file in the Google Chrome browser?

Currently I’m doing it like this:

document.head.innerHTML += '<script src="http://example.com/file.js"></script>';

Answer

Harmen picture Harmen · Mar 12, 2011

appendChild() is a more native way:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'script.js';
document.head.appendChild(script);