javascript/jQuery location.href未命中标记

javascript/jQuery location.href未命中标记,javascript,jquery,dom,Javascript,Jquery,Dom,我有一个页面,其中有许多元素在启动时向上滑动。我希望能够根据我的代码所在的url中的哈希值向下滑动特定窗格 if (window.location.hash.length>0){ var id = window.location.hash; if (id.length==7){ //expected hash is 7 chars long (inc #) console.log('Comment hash in url, finding link');

我有一个页面,其中有许多元素在启动时向上滑动。我希望能够根据我的代码所在的url中的哈希值向下滑动特定窗格

    if (window.location.hash.length>0){

   var id = window.location.hash;

   if (id.length==7){ //expected hash is 7 chars long (inc #)

    console.log('Comment hash in url, finding link');

    $(id).parents('.details_wrapper').parent().show().find('.details_wrapper').addClass('open').slideDown('slow', function(){ //unhide and slidedown pane
     window.location.href = id;
    });
   }
  }
在适当的窗格被显示并向下滑动的情况下,哪种方式起作用,但是window.location.href似乎工作得不太好,因为窗口始终将页面放置在比锚定位置低800px的位置

作为一个可能的旁注,我似乎无法在键入时验证正确的href

window.location.href='#c83225';

Safari在开发人员控制台中给出了一个错误。但它可以在Chrome控制台中工作。

另一个选项是

window.location.hash = 'c83225';