最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Don't allow refresh webpage - Stack Overflow

programmeradmin2浏览0评论

I have a link:

<a href="#" onClick="javascript:isRename();" class="current-text">rename</a>

which invokes isRename() function:

function isRename(){    
var i = getCheckboxCount(); 
if(i==1){   
    showInputDialog(getCheckboxName(),'Rename', 'Enter the name of file/directory',null);
}   
}

function showInputDialog(a,b,c,okFunc){ 
$.fn.InitInputDialog(a,b,c,okFunc);
$.fn.fadeInCommon(); 
};

It shows a modal window. This window has a close button.

$("#CloseInputButton").off('click'); //MY CLOSE BUTTON IN MODAL WINDOW      
    $("#CloseInputButton").click(function(){
        fadeOutCommon();            
    }); 

$.fn.fadeOutCommon = function(){        
    //transition effect
    $('#mask').fadeTo("slow",0.0,function(){
        $(dialogID).hide();     
        $('#mask, .window').hide();
    });     

};
It works fine before I press the close button. My web page refreshes and fadeOutCommon animation doesn't work at all! I think it happens because of refreshing web page! How can I disable refreshing web page? Thanks

I have a link:

<a href="#" onClick="javascript:isRename();" class="current-text">rename</a>

which invokes isRename() function:

function isRename(){    
var i = getCheckboxCount(); 
if(i==1){   
    showInputDialog(getCheckboxName(),'Rename', 'Enter the name of file/directory',null);
}   
}

function showInputDialog(a,b,c,okFunc){ 
$.fn.InitInputDialog(a,b,c,okFunc);
$.fn.fadeInCommon(); 
};

It shows a modal window. This window has a close button.

$("#CloseInputButton").off('click'); //MY CLOSE BUTTON IN MODAL WINDOW      
    $("#CloseInputButton").click(function(){
        fadeOutCommon();            
    }); 

$.fn.fadeOutCommon = function(){        
    //transition effect
    $('#mask').fadeTo("slow",0.0,function(){
        $(dialogID).hide();     
        $('#mask, .window').hide();
    });     

};
It works fine before I press the close button. My web page refreshes and fadeOutCommon animation doesn't work at all! I think it happens because of refreshing web page! How can I disable refreshing web page? Thanks

Share Improve this question asked Mar 22, 2012 at 6:02 NoleshNolesh 7,02812 gold badges78 silver badges113 bronze badges 2
  • 1 You possibly won't need to "disable refresh", as a sidenote: disabling refresh on user's browser is what I would consider offensive and frustrating... Either change your UI design or deal with it. – Andreas Wong Commented Mar 22, 2012 at 6:04
  • onClick="javascript:isRename();" <- you're mixing handler syntax with href syntax. javascript: shouldn't be there. – SpliFF Commented Mar 22, 2012 at 6:12
Add a ment  | 

2 Answers 2

Reset to default 3

Just write down return false; will do that task.

<a href="#" onClick="javascript:return isRename();" class="current-text">rename</a>

    function isRename(){     
    var i = getCheckboxCount();  
    if(i==1){        
         showInputDialog(getCheckboxName(),'Rename', 'Enter the name of file/directory',null); }    
    return false;
    }  

Also have look to

e.preventDefault() will prevent the default event from occuring, e.stopPropagation() will prevent the event from bubbling up and return false will do both.

you can put return false in your click methods

$("#CloseInputButton").click(function(){
    fadeOutCommon();  
 return false;          
}); 
发布评论

评论列表(0)

  1. 暂无评论