Answer the question
In order to leave comments, you need to log in
Show/Hide cookie block, problem with spaces?
There is a script like this:
<script>
function _setCookie(name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
function show_hide(num_id) {
var divstyle = new String();
divstyle = document.getElementById(num_id).style.display;
if (divstyle.toLowerCase() == "none" || divstyle == "") {
document.getElementById(num_id).style.display="block";
var date = new Date( new Date().getTime() + 1000*60*60*24*365); // ставим куку на 365 дней
_setCookie(num_id, escape("block"), date.toUTCString(), "/");
} else {
document.getElementById(num_id).style.display="none";
var date = new Date( new Date().getTime() + 1000*60*60*24*365); // ставим куку на 365 дней
_setCookie(num_id, escape("none"), date.toUTCString(), "/");
}
}
</script>
<div onclick="show_hide('block_1');">click</div>
<div id="block_1" style="display:<?=isset($_COOKIE['block_1'])? $_COOKIE['block_1'] : 'none'; ?>">content 1 по умолчанию скрыт</div>
<br />
<div onclick="show_hide('block_2');">click</div>
<div id="block_2" style="display:<?=isset($_COOKIE['block_2'])? $_COOKIE['block_2'] : 'none'; ?>">content 2 по умолчанию скрыт</div>
<br />
<div onclick="show_hide('block_3');">click</div>
<div id="block_3" style="display:<?=isset($_COOKIE['block_3'])? $_COOKIE['block_3'] : 'block'; ?>">content 3 по умолчанию показан</div>
<br />
<div onclick="show_hide('block_4');">click</div>
<div id="block_4" style="display:<?=isset($_COOKIE['block_4'])? $_COOKIE['block_4'] : 'block'; ?>">content 4 по умолчанию показан</div>
<span id="span_pm" class="<?=isset($_COOKIE['span_pm'])? $_COOKIE['span_pm'] : 'glyphicon glyphicon-minus'; ?>" ></span>
Answer the question
In order to leave comments, you need to log in
%20 is an encoded space. Appears due to the use of escape().
Where is it returned? What do you have in mind?
The class doesn't change. This script does not even attempt to change any class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question