3

What I currently have:

  • index.php: Mainpage, showing topbar, navigation & placeholder for content

  • navigation: uses javascript to load a php-file into the content-section from index.php if a link in the navigation is clicked; important: NO refresh of index.php

Is working fine right now. Also the url in the address bar is not being changed right now when clicking a link.

What should be added:

If a link in the navigation is clicked, javascript should still load a php-file but also should change the url in the address bar without refreshing the side.

Example:

  • url: "www.example.com
  • In navigation link "work" is clicked.
  • work.php is loaded into the content-section of index.php
  • url now: "www.example.com/work

Additionally if the user types www.example.com/work in the address bar index.php should load work.php without a link being clicked.

A good example to understand my issue with the url in the address bar is facebook. Hope I could clarify my problem so somebody is able to help me ;-)

4

2 回答 2

0

您只能在不刷新页面(发出另一个请求)的情况下更改 URL 的主题标签。因此,当单击导航链接时,您可以将“www.example.com”更改为“www.example.com/#work”,但如果不重新加载页面,则无法将其更改为“www.example.com/work”。

可以使用 javascript 使用 window.location.hash 设置主题标签

window.location.hash = "work";
于 2012-12-15T11:23:23.843 回答
0

如果您希望避免使用主题标签,可以使用HTML5 历史 API。这允许你/在你的页面中使用history.pushState()and history.replaceState()方法。还有一个你可能会觉得有用的插件。

于 2012-12-15T11:43:13.640 回答