将JavaScript添加到OpenCart中的所有页面 [英] Adding a javascript to all pages in OpenCart
问题描述
我是OpenCart的新手,没有任何PHP经验,所以我有一个问题。我想添加以下JavaScript来隐藏移动浏览器上的网址栏
I'm new to OpenCart and don't have any experience with PHP, so I have a question. I want to add the following JavaScript to hide the url bar on mobile browsers
// When ready...
window.addEventListener("load",function() {
// Set a timeout...
setTimeout(function(){
// Hide the address bar!
window.scrollTo(0, 1);
}, 0);
});
但是,我找不到插入此方法的方法,因此这段代码将在所有页面上执行在OpenCart中。我应该把这段代码放在哪里?
However, I can't find a way to insert this so this code will be executed on all pages in OpenCart. Where should I put this code?
推荐答案
将脚本保存到文件中,比如'catalog / view / javascript / myscript.js '
save your script to a file, say 'catalog/view/javascript/myscript.js'
然后添加
$this->document->addScript('catalog/view/javascript/myscript.js');
到目录/ controller / common / header.php 之前的某个地方这一行:
to the catalog/controller/common/header.php some place before this line:
$this->data['scripts'] = $this->document->getScripts();
您也可以将脚本内联到目录/视图/主题/ {主题名称} /template/common/header.tpl 使用普通的html标记。
You could also just place your script inline into catalog/view/theme/{theme name}/template/common/header.tpl using normal html markup.
这篇关于将JavaScript添加到OpenCart中的所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!