2016-07-06 10 views
0

私はMagento 1.7を自分のWebサイトで実行しており、JSファイルをページの最下部に移動しようとしています。私は私が私のレイアウトファイルにこれを追加したガイドが続い:JSファイルを</body>タグの直前に移動Magento

<reference name="before_body_end"> 
     <block type="page/html_head" name="foot" as="foot" after="-" template="page/html/foot.phtml"> 
      <action method="addJs"><script>lib/injectIn.js</script></action> 
     </block> 
</reference> 

は、これは私のウェブページのすべての主な内容以下のJSファイルを移動しますが、それよりも低く、いくつかの他のものがまだあります。閉じた</body>タグの前にJSファイルを移動する方法があるのだろうかと思います。

例えば、私は移動しましJSファイルブロック以下のものが追加されますこのような私のレイアウトファイル内のブロックを持っています。ここでは

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"> 
     <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/> 
     <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/> 
</block> 

はクロームで、ソースコードの一部の絵である、など

enter image description here

答えて

0

あなたは、ヘッド部にJSを呼び出すことができますbodyタグの直前に呼び出されます。

使用<reference name="head">

-1

あなたは次のようにjavascriptのは、appendChild関数を使用することができます:

あなたはJSファイルの下にいくつかのものを置く見ることができます0

まず、あなたは(あなたのケース本体に)に追加する要素を得る:

var elBody = document.getElementsByTagName("body"); 

次はあなたのためにあなたがクラスであなたのケースのDIVに(追加したいHTMLをコンテナを作成し、「メイン・コンテナcol1-レイアウトコンテナ」)としたいhtmlの追加:最後のステップは、親要素(ボディ)に要素を追加

var newEl = document.createElement('div'); 

newEl.className += " main-container col1-layout container"; 

newEl.innerHTML = '<script type="text/javascript" src="url/file1.js"></script>' + '<script type="text/javascript" src="url/file2.js"></script>' 

を:それはあるよう

elBody.appendChild(newEl); 
関連する問題