How to ignore jquery variable?
I have code, that looks something like this:
(function($) {
$(document).ready(function() {
function getHash(){
var h = document.location.href.split('#');
return h.length == 1 ? "" : h[1];
}
var $newdiv = $('...html code here...');
function checkit() {
if(getHash() != "#ignoreDivButton")
$('html').html($newdiv);
}
checkit();
$('#ignoreDivButton').click(function(){
document.location.href = document.location.href.split('#')[0] + "#ignoreDivButton";
location.reload();
});
});
})(jQuery);
What I need, is to reload page by clicking on #ignoreDivButton but without loa开发者_运维问答ding the newdiv. I just can't get how to ignore the variable. Thank you in advance.
can set a variable into a cookie, localStorage or even into the url(hash) :
function getHash(){
var h = document.location.href.split('#');
return h.length == 1 ? "" : h[1];
}
$(window).load(function() {
if(getHash() != "ignoreDivButton")
$('html').html($newdiv);
});
$('#ignoreDivButton').click(function(){
//reload the page and set the hash of the url to ignoreDivButton
document.location.href = document.location.href.split('#')[0] + "#ignoreDivButton";
})
How about instead of just reloading the location, you append some sort of tag to the URL, like #second_load
and then test for the token in the URL before setting your $newdiv
variable?
Looks like it will always load newdiv right now, simply because you never limited it, try having a variable in a cookie that states whether the div should be loaded or not (you can simply use javascript for this.. check out a website like w3schools if you don't know how to use them).
Then simply add an if statement before the $('html').html($newdiv);
精彩评论