Answer the question
In order to leave comments, you need to log in
Why is the style not saved on different js pages?
There is a script for adding a css file to replace the styles of some elements
. After clicking on 1 of the options, everything works and switches.
But this is Opencart 2.3, and when you navigate to other pages, the style is reset. That is, the default style (empty) is written again, but for this page.
How to cut or fix so that the transition does not take into account the path or what would work on all pages?
Here is the code for the script and buttons.
<!DOCTYPE html>
<html>
<head>
<title>Название страницы</title>
<!-- CSS -->
<link href="catalog/view/theme/angar/stylesheet/stylesheet.css" rel="stylesheet"><!-- Стандартный стиль -->
<script>
function getcookie(name) {
var aCookie = document.cookie.split(';');
for (var i = 0; i < aCookie.length; i++) {
while (aCookie[i][0] == ' ') {
aCookie[i] = aCookie[i].substr(1);
}
var aCrumb = aCookie[i].split('=');
if (name == aCrumb[0]) {
return unescape(aCrumb[1]);
}
}
return null;
}
function setcookie(name, value, expires, path, domain, secure) {
var today = new Date();
var expires_date = new Date(today.getTime() + (expires * 1000));
document.cookie = name + '=' + escape(value) + (expires ? ';expires=' + expires_date.toUTCString() : '') + (path ? ';path=' + path : '') + (domain ? ';domain=' + domain : '') + (secure ? ';secure' : '')
}
if (getcookie('myStyle9') == null) {
setcookie('myStyle9', 'catalog/view/theme/angar/stylesheet/stylesheet_default.css')
}
var myStyle9 = getcookie('myStyle9');
document.write('<link type="text/css" rel="StyleSheet" href="'+myStyle9+'" />')
</script>
</head>
<body>
<!-- Dop Style -->
<div class="btn-group dropup">
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown">Цвет сайта</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="javascript://" onclick="setcookie('myStyle9', 'catalog/view/theme/angar/stylesheet/stylesheet_default.css');window.location.reload()" id="default">Стандартный</a></li><!-- Пустой файл -->
<li><a href="javascript://" onclick="setcookie('myStyle9', 'catalog/view/theme/angar/stylesheet/stylesheet_blue.css');window.location.reload()" id="blue">Синий</a></li><!-- Меняет некоторые элементы -->
<li><a href="javascript://" onclick="setcookie('myStyle9', 'catalog/view/theme/angar/stylesheet/stylesheet_green.css');window.location.reload()" id="green">Зеленый</a></li><!-- Меняет некоторые элементы -->
</ul>
</div>
<!-- Dop Style -->
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question