开发者

Refresh page when url hash is present

I have a navig开发者_高级运维ation system on my site that uses javascript to slide horizontally stacked divs left and right into view. I'm trying to make the site function better with javascript turned off, so I have a second navigation system that uses hash values to 'go to' the appropriate section.

The problem arises if someone is on say http://mysite.com/#page2 then turns javascript on. The page reloads at the #page2 section which then causes the javascript enabled navigation system to not work correctly. e.g. it reloads thinking the page is at section 1 when it is actually displaying section #whatever.

I have tried adding parent.location.hash = ''; but when the page reloads, it still stays on whichever section it was on.

Any ideas on how to make the page fully refresh when javascript gets turned on?


Haven't tested this but, you could have a javascript state variable. When javascript first executes, it sets the state variable to true, checks if the url is the base one or a page section, then reloads to the root url (mysite.com). If the state variable is already true, it won't reload the page (so that you don't continually reload). Since the variable is in the javascript engine, it wouldn't be set to true yet if javascript just got turned on.

Here is an example of using javascript to parse the URL. In your case you'd pretty much just be looking for the # symbol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜