1

我对 prestashop 1.7 有以下问题

  1. 我用钩子注册静态javascriptactionFrontControllerSetMedia
  2. 我尝试使用相同的方法注册动态远程加载的 javascript:
    • 当然,它不像registerJavascript预期的本地路径那样工作。
    • Context->addJs()不再适合我了。

有什么解决方案如何将javascript添加到文档中?

4

5 回答 5

2

如果您需要为所有页面或特定页面添加 JavaScript/CSS,您可以使用 theme.yml 来更新它。例如,如果您需要在所有页面上添加以下两个外部 CSS。在你的 theme.yml 中添加以下内容:

....
    css:
       all:     
         - id: fontawesome-css
           path: https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css
           media: all
           priority: 200
           inline: false
           server: remote
         - id: googlecss
           path: https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,600,700,800
           media: all
           priority: 200
           inline: false
           server: remote
....
于 2017-10-27T05:50:55.087 回答
1

见:https ://github.com/PrestaShop/PrestaShop/pull/7022 (1.7.0.2引入)

$this->registerJavascript(
   'remote-bootstrap',
   'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',
   ['server' => 'remote', 'position' => 'head', 'priority' => 20]
);
于 2016-12-06T16:59:41.127 回答
0

在您的任何 JS 文件中添加以下代码,它将加载远程 JS 文件:

function loadScript() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://my.remote.js';
    document.body.appendChild(script);
}
于 2016-12-02T04:09:26.970 回答
0

似乎它已在1.7.0.2 https://github.com/PrestaShop/PrestaShop/pull/7022中重新引入, 他们将使用registerJavascriptregisterStylesheet代替。

$this->registerJavascript('remote-bootstrap-head', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', ['server' => 'remote', 'position' => 'head', 'priority' => 20]);
$this->registerJavascript('remote-bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', ['server' => 'remote', 'position' => 'bottom', 'priority' => 20]);
$this->registerStylesheet('remote-bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', ['server' => 'remote', 'priority' => 20]);
于 2016-12-06T17:05:25.060 回答
-1
$this->context->controller->registerJavascript(
    'remote-openpay-js',
     'https://openpay.s3.amazonaws.com/openpay.v1.min.js',
     ['position' => 'bottom', 'server' => 'remote']
);
于 2016-12-26T20:05:08.770 回答