2011-10-11 34 views
0

我在我的网站上有这个内容框,它有不同的标签,当你点击其中一个标签时,它使用JS来隐藏/显示内容中的相应div框。问题w/window.location.hash

我也有这个在我的头给每个DIV内容框里面它自己的网址:

<script type="text/javascript"> 
    function loadSmugInfo() { 
    if(window.location.hash == '#smuginfo') 
     document.getElementById('contentInfo').style.display = "block"; 
     document.getElementById('contentSlideshow').style.display = "none" 
    } 
</script> 

<script type="text/javascript"> 
    function loadFind() { 
    if(window.location.hash == '#find') 
     document.getElementById('contentMap').style.display = "block"; 
     document.getElementById('contentSlideshow').style.display = "none" 
    } 
</script> 

<script type="text/javascript"> 
    function loadSmugmug() { 
    if(window.location.hash == '#smugmug') 
     document.getElementById('contentSmugInfo').style.display = "block"; 
     document.getElementById('contentSlideshow').style.display = "none" 
    } 
</script> 

<script type="text/javascript"> 
    function loadMain() { 
    if(window.location.hash == '#') 
     document.getElementById('contentSlideshow').style.display = "block" 
    } 
</script> 

<script type="text/javascript"> 
    function loadSlideshow() { 
    if(window.location.hash == '#slideshow') 
     document.getElementById('contentSlideshow').style.display = "block" 
    } 
</script> 

我也有它所以当你点击一个标签,它改变了哈希值。

这是我的问题。 当页面像普通(没有散列)一样加载时,第一个和最上面的div仍然不显示(即使它设置为在CSS中显示:block)。

我正在加载上面看到的函数,在内容框上方的图像上使用onLoad。

任何帮助将不胜感激,我有点紧张的时间表。 让我知道你是否需要更多信息。 谢谢!

+3

旁边的问题:你为什么要用se为每个功能分配'

1

这里有几个问题。

首先,你不显示任何方式调用这些函数。您可能想要启动间隔计时器来轮询这些函数并定期检查它们。这将确保他们在页面加载时进行评估,并且每次散列更改。

您还在评估散列==“#”是否为默认值,但不会在初始页面加载时显示。也许把一个AND调查,以检查它是否==“”以及。

这是我用于散列轮询的一些代码示例。也许它可以帮助。

var start_hash = window.location.hash; 
var recent_hash = ''; 

process_hash(start_hash);  // Start the initial hash check 
setInterval(poll_hash, 100); // Initialize our hash polling interval 

function poll_hash() { 
if (window.location.hash==recent_hash) { return; } // No change in URL hash 
recent_hash = window.location.hash;    // Set to check next time. 
process_hash(recent_hash);       // Changed hash, lets process 
} 

function process_hash(current_hash) { 
// Check for defaults, then set to #home. 
if(!current_hash || current_hash == '' || current_hash == '#') 
    { current_hash='#home'; } 

// Strip the # for the hash 
var hash_id = current_hash.match(/[^#]+/g);     

if(hash_id == 'home') { do something; } 
} 
-2

试试这个:

<script> 

    document.domain = 'facebook.com'; 
    try { 
     try { 
     if (window.opener && window.opener.graphexplorer) {  
      window.opener.graphexplorer.authCallback(window.location.hash); 
     } 
     } catch(e) { } 
    } catch (e) { } 
    window.location.hash = ''; 
    window.close(); 

</script>