문제

내 테마의 맨 위에 스타일 스위처 바가 있습니다. 대부분은 작동하지만 새로운 스타일을보기 위해 F5를 치거나 새로 고침해야합니다. 성공적인 실행에 따라이 jQuery를 자동 재생으로 완료하려면 어떻게해야합니까?

    jQuery.fn.styleSwitcher = function(){
    $(this).click(function(){
        loadStyleSheet(this);
        return false;
    });
    function loadStyleSheet(obj) {
        $('body').append('<div id="overlay" />');
        $('body').css({height:'100%'});
        $('#overlay')
            .css({
                display: 'none',
                position: 'absolute',
                top:0,
                left: 0,
                width: '100%',
                height: '100%',
                zIndex: 1000,
                background: 'black url(http://mytheme.com/loading.gif) no-repeat center'
            })
            .fadeIn(500,function(){
                $.get( obj.href+'&js',function(data){
                    $('#stylesheet').attr('href','css/' + data + '.css');
                    cssDummy.check(function(){
                        $('#overlay').fadeOut(500,function(){
                            $(this).remove();
                        }); 
                    });
                });
            });
    }
    var cssDummy = {
        init: function(){
            $('<div id="dummy-element" style="display:none" />').appendTo('body');
        },
        check: function(callback) {
            if ($('#dummy-element').width()==2) callback();
            else setTimeout(function(){cssDummy.check(callback)}, 200);
        }
    }
    cssDummy.init();
}
$.ajax({
  success:function(){
       $('#overlay').load('http://mytheme.com');
  }
 });
도움이 되었습니까?

해결책

당신이 사용할 수있는

success: function() {
    window.location.reload(true);
}

다른 팁

window.location.reload(true); 

트릭을 할 것입니다.

window.location = window.location.pathname 새로 고침을 수행합니다.

이것을 사용할 수 있습니다. 도움이 될 수 있습니다

이 코드를 얻었습니다 페이지를 새로 고치려면

success: function(data){
   if(data.success == true){ // if true (1)
      setTimeout(function(){// wait for 5 secs(2)
           location.reload(); // then reload the page.(3)
      }, 5000); 
   }
}

당신이 사용할 수있는:

document.location.reload();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top