2013-04-17 64 views
3

我在fancybox 1.3.7中使用此代码。当fancybox打开url更改到相应的div(/ page#div-id)时,它关闭时应该返回到/ page但注释的函数不起作用。我不得不使用如下所示的临时值。我怎样才能解决这个问题?打开和关闭fancybox时更改url

window.onload = function(){ 
    function showfb(id) { 
     if (/^#.*/.test(id)) { 
      $(id).show(); 
      $.fancybox({ 
       href: id, 
       type:'inline', 
       position: 'center', 
       'transitionIn': 'fade', // elastic, none, ease, fade 
       'transitionOut': 'fade', 
       onClosed: function(){ 
        //$(id).hide(); 
        window.location.hash = "_"; // temporary 
       } 
      }); 
     } 
    } 
    showfb(location.hash); 
    $('a.profile').click(function(e){ 
      showfb($(this).attr('href')); 
    }); 
}; 
+0

你为什么这样做'$( 'a.profile')点击(函数(E){showfb($(本).attr ('href'));});'而不是'$('a.profile')。fancybox()'? – JFK

回答

2

尝试用下面的替换功能:

window.location.hash = ""; 
+0

我这样做了,但#仍然留在那里,尽管页面在顶部滚动... –

+0

我会使用“”(内部有一个空格),以便页面不会向上滚动!日Thnx! –