简体   繁体   English

单击html5中的按钮/链接时如何将一个页面导航到另一个页面

[英]how to navigate one page to another page when click on button/link in html5

I have a link/button in html page . 我在html页面中有一个链接/按钮。 when i click the button i have to populate another page data as a model popup in the current page. 当我点击按钮时,我必须将另一个页面数据填充为当前页面中的模型弹出窗口。 I used bootstrap model for popup . 我使用bootstrap模型进行弹出。 Is this possible without call server to navigate the page and wihtout jquery/any server side technologies. 如果没有呼叫服务器来导航页面并且没有jquery /任何服务器端技术,这是否可行。 I need to used simple java script to do this. 我需要使用简单的java脚本来执行此操作。

If you want to populate your modal with information, and you want this information to persist (not just append HTML on it). 如果要使用信息填充模态,并且希望此信息保持不变(不仅仅是在其上附加HTML)。 Yes, you'll need in some manner to communicate with the server so it can update your content. 是的,您需要以某种方式与服务器通信,以便更新您的内容。

Actually there's no way to populate persistent content, given a user action, without talking with the server . 实际上,在没有与服务器通信的情况下,无法给定用户操作的情况下填充持久性内容 (ie you refresh the page and its still there to see) (即你刷新页面,它仍然在那里看)

Since you asked an HTML5 solution, we have the Fetch API. 由于您询问了HTML5解决方案,因此我们提供了Fetch API。 Fetch was designed to be easier and broader than XMLHttpRequest. Fetch被设计为比XMLHttpRequest更容易和更广泛。 To quote MDN: 引用MDN:

The Fetch API provides an interface for fetching resources (eg, across the network.) It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set. Fetch API提供了一个用于获取资源的接口(例如,通过网络。)对于使用XMLHttpRequest的人来说,这似乎很熟悉,但新API提供了更强大,更灵活的功能集。

My guess is that you want to post information on your modal. 我的猜测是你要在你的模态上发布信息。 Supposing you want to send a form data to your modal: you'll want to use something like this: 假设您要将表单数据发送到模态:您将要使用以下内容:

fetch('http://your-website-goes-here.com/submit-data', {
  method: 'post',
  body: JSON.stringify({
    name: document.getElementById('name').value
    email: document.getElementById('email').value
    message: document.getElementById('message').value
  })
})

Notice that not all browsers supports Fetch, which uses ES6 promises . 请注意,并非所有浏览器都支持使用ES6 承诺的 Fetch。 Nothing that a good polyfill wouldn't solve. 没有什么好的polyfill不会解决。 More about it on Can I Use. 关于它的更多信息我可以使用。 See Fetch and Promise support. 请参阅获取承诺支持。

For further info about Fetch, I'd recommend the following: 有关Fetch的更多信息,我建议如下:

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM