开发者

Javascript: Creating a 'weird' conditional re-direct

If I had a normal website this would be a simple enough fix... but I've built my site on tumblr so I need a workaround. Every page runs off of the same code, so any solution script is going to run on every page.. can't quite figure this one out (did I mention I'm a tota开发者_如何学编程l n00b?). There are lots of answers to questions LIKE this one, but I couldn't quite find the right syntax I suppose to answer this question...

The goal here is, if some goes to just the raw domain name, in this case milliondollarextreme.tv --> I'd like it to redirect to milliondollarextreme.tv/tagged/videos.

In any other case, by that I mean, if there is anything appended to the end of the domain name already, such as:

  • milliondollarextreme.tv/permalink/91298132843
  • milliondollarextreme.tv/tagged/blog
  • milliondollarextreme.tv/contact.htm

I don't want there to be any redirection going on. I only want the redirect to 'fire' really the first time the person types in the domain -- milliondollarextreme.tv

The trick here, the reason why I am asking (I did a search and 1000 apologies if this has been asked elsewhere, I just couldn't find it) is that the script has to run on every page, because it's hosted on tumblr, so every page is driven by the same code.

Any ideas? Thanks in advance.


This will simply redirect any visit to milliondollarextreme.tv/ to milliondollarextreme.tv/tagged/videos

if(window.location.pathname == '/')
{
  window.location.pathname = '/tagged/videos';
}

However, it will do it every time they go to the root; like Gerardo, I'm not clear if that's what you want.


<script>
if( window.location.href == "http://milliondollarextreme.tv"   ||
    window.location.href == "http://milliondollarextreme.tv/"  ||
    window.location.href == "http://www.milliondollarextreme.tv"   ||
    window.location.href == "http://www.milliondollarextreme.tv/") {

  window.location.href = "http://www.milliondollarextreme.tv/tagged/videos/";

}
</script>

What should happen when someone enters to http://milliondollarextreme.tv/ for the second time?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜