开发者

How can I design a site like Stack Overflow with a constant menu at the top and only a body that refreshes?

开发者 https://www.devze.com 2023-02-09 10:45 出处:网络
How would I go about designing a site with a si开发者_JAVA技巧milar layout to Stack Overflow (top menu bar that is always visible) and content body that reloads. I tried using ajax .load() to load in

How would I go about designing a site with a si开发者_JAVA技巧milar layout to Stack Overflow (top menu bar that is always visible) and content body that reloads. I tried using ajax .load() to load in content to the main area but then I have issues with JavaScript not working. How does Stack Overflow accomplish this? I would like to do this in PHP.


This is something that some browsers (like Chrome) do whenever there is a constant stylesheet and layout. It appears to not reload some parts of the page because they don't change. They are, however, reloaded every time you click a link.

So to achieve this effect you should use a good layout with certain aspects that don't change on every click.


That's definitely a complicated question but I can address your issue with javascript not working, if I understand it correctly.

The problem (in simplified form) is of course that you don't have some elements (from, for example, "page2") when you first load the site (which is when JS loads), but when you use ajax.load() to load "page2" instead of "page1" the JS code doesn't reload and so whatever stuff you were doing with elements on "page2" doesn't work.

You do have to manually call the relevant functions when you load "page2". Now, if you just have events (like onclick, etc.) attached to various elements on "page2" then you could use live events in jQuery (if that's an option), which can be attached to non-existent objects and will become active when the object is created, in this case via ajax.load().

0

精彩评论

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