简体   繁体   English

在页面之间导航而不更改链接

[英]Navigate between pages without changing the link

This question might have been asked in the past but I cannot seem to find the answer. 过去曾有人问过这个问题,但我似乎找不到答案。 I would like to navigate between pages without avec to redirect to a brand new xxx.html file. 我想在没有avec的页面之间导航以重定向到全新的xxx.html文件。 Basically, I want to keep only one html file being the index.html 基本上,我只想保留一个html文件作为index.html

In order to understand what I mean, here is a small preview of this functionality I want to achieve. 为了理解我的意思,这里是我要实现的功能的小预览。

Preview 预习

As you can see, the piece of clothing is not its individual html file. 如您所见,这件衣服不是其单独的html文件。 What method is used to achieve this? 用什么方法可以做到这一点?

What you are seeing is called a Single-Page-Application. 您所看到的称为单页应用程序。 There are a lot of frameworks with which you can create a page like this. 您可以使用许多框架来创建这样的页面。 If you are going for plain HTML/CSS/JavaScript it will be a lot harder to do correctly. 如果您要使用纯HTML / CSS / JavaScript,则正确执行起来会困难得多。

You will have to use javascript for this. 您将必须使用javascript。 Either you can load all content at once and just show/hide the content you need, or you could ajax to fetch the content and then render it without page reload. 您可以一次加载所有内容并仅显示/隐藏所需的内容,或者可以ajax来获取内容,然后呈现它而无需重新加载页面。

What you're seeing here is a dynamic webpage that is taking advantage of client-side technology to create this effect. 您在这里看到的是一个动态网页,该网页利用了客户端技术来产生这种效果。 To help further explain, let's quickly go over some web development terminology: 为了帮助进一步解释,让我们快速浏览一些Web开发术语:

Client-Side: Code that is executed on the user's computer (in this case in their web browser). 客户端:在用户计算机上执行的代码(在这种情况下,在其Web浏览器中)。

Server-Side: Code that is executed on a server, then a response of some sort is sent to the client. 服务器端:在服务器上执行的代码,然后将某种响应发送到客户端。

With server-side code, the value cannot change unless a new call is made to the server to get a new response. 使用服务器端代码,除非对服务器进行新的调用以获取新的响应,否则该值无法更改。 This is because the code isn't actually running on the computer the user is running, it's running on some other computer probably thousands of miles away. 这是因为代码实际上并没有在用户正在运行的计算机上运行,​​而是在可能相距数千英里的其他计算机上运行。 However, with client-side code, dynamic changes could be made in real-time because the code is actually running on the user's computer. 但是,使用客户端代码,因为代码实际上在用户计算机上运行,​​所以可以实时进行动态更改。

When it comes to server-side code, we as developers have a myriad of options. 当涉及服务器端代码时,我们作为开发人员有许多选择。 Any language that can send an HTTP response to a web browser could theoretically be used as a server side language. 从理论上讲,可以将HTTP响应发送到Web浏览器的任何语言都可以用作服务器端语言。 In 2018, that's basically every major language in existence! 在2018年,基本上所有基本语言都存在! That being said, some popular options today include Python, Ruby, Java, and Javascript (Node JS). 话虽如此,当今一些流行的选项包括Python,Ruby,Java和Javascript(Node JS)。

When it comes to client-side code, however, we're limited by what can run in a user's web browser. 但是,当涉及到客户端代码时,我们受到用户网络浏览器中运行内容的限制。 In general, modern web browsers only understand Javascript. 通常,现代Web浏览器仅了解Javascript。 However, while the language has gotten better over the years, writing code in pure JavaScript can sometimes be cumbersome, so there are libraries that help make writing Javascript easier (such as jQuery) and there are even languages that compile down to Javascript to add new syntax and functionality (such as Typescript and Coffeescript). 但是,尽管这些年来语言已经变得越来越好,但是有时用纯JavaScript编写代码有时会很麻烦,因此有些库可以帮助简化Java脚本的编写(例如jQuery),甚至有一些语言可以编译成Java脚本以添加新的语法和功能(例如Typescript和Coffeescript)。

If you'd like to start writing dynamic web applications, a good place to start would be to learn the basics of JavaScript . 如果您想开始编写动态Web应用程序,那么一个不错的起点是学习JavaScript的基础知识。 Then, maybe start learning jQuery , or front-end libraries such as Angular or React . 然后,也许开始学习jQueryAngularReact之类的前端库。 Good luck! 祝好运!

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

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