Reputation: 2552
I am having following issue with prestashop 1.7
actionFrontControllerSetMedia
registerJavascript
expects local path.Context->addJs()
doesn't work for me anymore.Is there any solution how to add javascript to the document?
Upvotes: 2
Views: 4449
Reputation: 680
In case you need to add the JavaScript/CSS for all pages or for a specific page, you can use theme.yml to update it. e.g. if you need to add following two external css on all of your pages. Add following in your 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
....
Upvotes: 2
Reputation: 172
$this->context->controller->registerJavascript(
'remote-openpay-js',
'https://openpay.s3.amazonaws.com/openpay.v1.min.js',
['position' => 'bottom', 'server' => 'remote']
);
Upvotes: -1
Reputation: 671
Seem like it has been reintroduced in 1.7.0.2 https://github.com/PrestaShop/PrestaShop/pull/7022 They will use registerJavascript and registerStylesheet instead.
$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]);
Upvotes: 0
Reputation: 66
See: https://github.com/PrestaShop/PrestaShop/pull/7022 (introduced in 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]
);
Upvotes: 2
Reputation: 1317
Add the following code in any of your JS file, it will load the remote JS file:
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://my.remote.js';
document.body.appendChild(script);
}
Upvotes: 0