简体   繁体   English

如何在使用时在导航栏上显示真实的网址

[英]How to show real url on the navigation bar when using <a href=“#” onclick=“funtion('test.php')”>

I tried to open the content pages in using a javascript. 我尝试使用javascript打开内容页面。 So, I don't have to write all the header and footer pages. 所以,我不必编写所有页眉和页脚页面。 However, there is a problem, the url is not show in the navigation bar. 但是,有一个问题,导航栏中没有显示网址。 Are there anyway to make the real url show up in the navigation bar? 反正有没有让真实的网址出现在导航栏中? http://www.page.com/test.php ? http://www.page.com/test.php

 <script> function openLink(url) { $( ".contentTable" ).load(url); } </script> 
 <a id="link1" href="#" onclick="openLink('test.php')">Link</a> 

It seems that you need to use the history api of your browser : 您似乎需要使用浏览器的历史记录api:

https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method

An example : 一个例子 :

history.pushState({}, "New page test", "/test.php");

First param is a state, second one a title and the third one your url. 第一个参数是一个状态,第二个是标题,第三个是你的网址。

pushState will add the entry to your history and replaceState will replace your current history state by a new one. pushState会将条目添加到您的历史记录中,而replaceState将用新的状态替换您当前的历史记录状态。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 让导航栏onclick / href在圆形元素上执行动画,然后加载新页面-如何? - Having a navigation bar onclick/href execute animation on a circle element then loading a new page - How? 当我试图将数据输入数据库时​​,不能POST /test.php给我这个错误 - Cannot POST /test.php when i am trying to enter data into database its given me this error 使用 JS 移除 onclick 功能 - Removing onclick funtion using JS 如何将onClick功能传递到使用字符串文字创建的范围? - How to pass onClick funtion into a span created using string literals? <a>单击其中的按钮时如何防止所有导航?</a> <a>例子:</a><a href="url1"></a> <a href="url2"><button>点击</button></a> - how to prevent all <a> navigation when a button inside it is clicked? example: <a href="url1"><a href="url2"><button>click</button></a></a> 复选框提醒脚本在动态加载包含复选框的test.php时不记得复选框状态 - Checkbox reminder script doesn't remember checkbox status when dynamically load test.php which contains the checkbox 如何在 jQuery on.append() 函数中的值为 NULL 时显示空字符串 - How to show empty string when value is NULL in jQuery on .append() funtion 如何将地址栏网址放入href属性 - How to Put Address bar url in href attribute 如何在onClick时将自定义href设置为按钮? - How to set a custom href into a button when onClick? 导航栏使用Ajax onclick - Navigation bar onclick with Ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM