开发者

I need a jQuery.history workaround for refreshing

I am using the jQuery.history plugin in my webpage and I am stuck with a little problem. I have the following layout for my webpage:

  • www.myDomain.com
  • www.myDomain.com/#home.php
  • www.myDomain.com/#otherPage.php
  • ... more of that

So when going to my website at www.myDomain.com, it actually loads index.php, which is quite logical. Inside index.php, I say: include('home.php');. So google can check the contents of my first page. $.history stores the www.myDomain.com link in its plugin. Which is still fine.

  1. Now, I go through my menu and click on Home. Which will direct me to my homepage. But of course, I was already there. The problem is that the link of my Home button is #home.php, because I do an ajax request with $.history. So my webpage fades out and the same content is coming in.

  2. When I am on otherPage and press ctrl+R, I first get my homepage and then the webpage is unloaded and otherPage comes in. Which is annoying, because I would like to get otherPage direct.

So my question is: How can I make sure, that the first page (so without a hash) is directly loaded when there is no hash? And how can I make sure that the homePage isn't loaded I am going to another hash?

It seems quite logical that it is going wrong, but I don't see the workaround, because PHP can't get the hash of the link. This is for the user agent only. And I was thinking about setting an extra variable or something when going to my page, but still, that would make the href's not the same anymore and $.history would not recognize the same links.

UPDATE开发者_运维知识库

This demonstration actually shows what I am talking about:

http://balupton.com/sandbox/jquery-ajaxy/demo/

When you are on the page and scroll down to the TABS section. Using jQuery Ajaxy as header; It shows an empty section. And clicking the tabs will fill it of course. When refreshing the page, it will again start with the empty page and then fill it with the right content you wanted. My thing is: I don't want a blank starting page.

Thanks in advance!


I would suggest instead of #home.php, try to make it only #home, that way it will not load two pages one by one and will load only one page.

Ref: http://plugins.jquery.com/project/jquery-history-web-2-0-hashchange-history-remote


Ok, so I created a workaround... finally.

In my main page, I do a standard include(). And do not set it to display: none. But I do so in a javascript later on with: document.write('<style>#content{display:none;}</style>');

So now, google will find the normal page. When someone loads the page. The first included page is just ignored. And because we init the $.history object, the page will do a $('#content').show(); after the first ajax call.

PS. I would like to mention that I should have start off with the jquery.address plugin, instead of this one. Maybe I'll refactor it someday.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜