开发者

Javascript - add anchor for design reasons

开发者 https://www.devze.com 2023-01-24 00:43 出处:网络
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/#welcome.

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/#welcome.

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

Is this开发者_JAVA百科 possible in some way? Maybe with window.location?

big thx for any help!


You could use window.location.hash here

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

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


window.onload = function ()
{
    window.location.hash = '#welcome';
    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/#welcome can be done using URL rewriting. See mod_rewrite for Apache installations or urlrewrite for IIS.net

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).

0

精彩评论

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

关注公众号