可能性の重複:
How to dynamically insert a <script> tag via jQuery after page load?headタグにスクリプトを追加する
私はこのコード
var scri = "<script type=\"text/javascript\">var _gaq = _gaq || []; _gaq.push(['setAccount','UA-22xxxxx3-15']); _gax.push(['_trackPageview']); <\/script>";
document.getElementsByTagName("script")[23].add(scri);
console.log(scri);
は私がの頭にその要素を追加したい持っていますドキュメントと私は.append().text().add()と他の多くのメソッドを試しましたが、私はいつもエラーを取得します。最後のものは
Uncaught TypeError: Object #<HTMLScriptElement> has no method 'add'
どのように私は頭の要素にこれを追加できますか?
あなたはjQueryライブラリをリンクしている:ちょうどちょうどこのようなあなたのコードを実行し、あなたのJSコードは、それを実行したいポイントでいくつかのインラインコードを実行する
? – Chase
http://stackoverflow.com/questions/3857874/how-to-dynamically-insert-a-script-tag-via-jquery-after-page-load – PeeHaa