Adam
Adam

Reputation: 735

External Javascript File with Script tags

I am using a javascript templating framework called ICanHazjs.com.

My questions is can I include tags inside of a external javascript file, and if so is there any downsides / compatibility issues with this?

And if I can't what can I attach that will let me add tags.

Upvotes: 3

Views: 836

Answers (3)

Bryan B
Bryan B

Reputation: 4535

ICanHaz supports adding templates at runtime with addTemplate. It's probably your best bet.

Upvotes: 1

GorillaMoe
GorillaMoe

Reputation: 4134

if you are only looking for scripts to append you can try this:

var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'foo_id';
script.src = 'myjs.js';
document.getElementsByTagName('head')[0].appendChild(script);

otherwise you might try

document.write('<h1>this is pretty ugly in here</h1>');

for document.write there are some common pitfalls :)

Upvotes: 2

Michael Berkowski
Michael Berkowski

Reputation: 270607

If you mean can you include HTML markup inside the Javascript file, no that will not work. The script will be parsed strictly as Javascript.

However, the included Javascript can create HTML markup and add it to the DOM.

Upvotes: 2

Related Questions