Adding external JavaScript file to Magento

trejderMagento Kid提出了一个问题:Adding external JavaScript file to Magento,或许与您遇到的问题类似。

回答者trejderOSdave给出了该问题的处理方式:

Put the JS file somewhere into the "js" folder, and in the XML layout you can include it with:

    <reference name="head">
        <action method="addJs"><script>folder/file.js</script></action>
    </reference>

Hope that helps.

Edit: You can also do it in your block:

    protected function _prepareLayout()
    {
        $this->getLayout()->getBlock('head')->addJs('path/from/js/folder/to/your/file.js');

        return parent::_prepareLayout();
    }

希望本文对你有帮助,欢迎支持JavaScript中文网