admin 管理员组

文章数量: 1086019

i have a tiny JS problem: If a user visits a special site i would like to automatically add an anchor to that url for design reasons -> result .

After 10 seconds i would like to change the anchor to

Is this possible in some way? Maybe with window.location?

big thx for any help!

i have a tiny JS problem: If a user visits a special site http://www.test.de i would like to automatically add an anchor to that url for design reasons -> result http://www.test.de/#wele.

After 10 seconds i would like to change the anchor to http://www.test.de/#thankyou

Is this possible in some way? Maybe with window.location?

big thx for any help!

Share Improve this question asked Nov 9, 2010 at 16:33 LupoLupo 3,1045 gold badges27 silver badges30 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

You could use window.location.hash here

window.onload = function(){
  window.location.hash = 'wele';

  setTimeout( function(){
    window.location.hash = 'thankyou';
  }, 10*1000);
};
window.onload = function ()
{
    window.location.hash = '#wele';
    setTimeout(function ()
    {
        window.location.hash = '#thankyou';
    }, 10*1000);
}

MDC window.onload() docs

MDC window.location.hash docs

The first part of your question - remapping www.test.de to www.test.de/#wele can be done using URL rewriting. See mod_rewrite for Apache installations or urlrewrite for IIS

The second could easily be done using a JavaScript timer and window.location as you have suggested.

<script type="text/javascript">
 setTimeout("window.location.href='http://www.test.de/#thankyou'", 10000); // 10 secs
</script>

Although I would question this approach from a user experience perspective. If you are actually referring to specific anchors within the document body, then the user might be dismayed to find his screen jumping to a new part of the page after 10 seconds. If there are no corresponding anchors, then it's just odd (though not necessarily bad).

本文标签: http redirectJavascriptadd anchor for design reasonsStack Overflow