简体   繁体   English

如何跨多个 web 页面携带唯一标识符

[英]How to carry a unique identifier across multiple web pages

I have created a simple website for my own use that consists of 3 static pages.我创建了一个简单的网站供我自己使用,其中包含 3 个 static 页面。 Each page loads some data from a database (parse server) that allows me to either view or manipulate said data.每个页面都从允许我查看或操作所述数据的数据库(解析服务器)加载一些数据。 This works great but now I want to expand it to select specific data based on an identifier ( dataid ).这很好用,但现在我想将它扩展到基于标识符( dataid )的 select 特定数据。

Assuming I go to a landing page and then select (eg from a dropdown) the dataset, by name, I want to view/edit which gives the dataid , how do I use that dataid across any of the 3 pages I have?假设我 go 到登录页面,然后 select (例如从下拉列表中)数据集,按名称,我想查看/编辑给出dataid ,我如何在我拥有的 3 个页面中的任何一个中使用该dataid

I thought about using localStorage but that is common for a given domain/port and I may want multiple tabs open each showing a different set of data (different dataid ).我考虑过使用 localStorage ,但这对于给定的域/端口很常见,我可能希望打开多个选项卡,每个选项卡显示一组不同的数据(不同的dataid )。

And I think sessionStorage is not the correct solution either since it only persists per tab and I'd like to be able to have multiple tabs open related to the same dataid .而且我认为 sessionStorage 也不是正确的解决方案,因为它只在每个选项卡上持续存在,我希望能够打开与同一个dataid相关的多个选项卡。

I think it might be related to query strings but I am not sure how to use that across all pages.我认为它可能与查询字符串有关,但我不确定如何在所有页面中使用它。 For example, assume from the landing page user selects dataid='dataset1' and the landing page opens main.html?dataset1 .例如,假设用户从登陆页面选择dataid='dataset1'并且登陆页面打开main.html?dataset1 But if main.html contains a link to edit.html how would I get it to open edit.html?dataset1 ?但是,如果main.html包含指向edit.html的链接,我将如何让它打开edit.html?dataset1 I have seen some solutions where all links on a page are modified using jQuery/javascript to append the query string;我见过一些解决方案,其中页面上的所有链接都使用 jQuery/javascript 修改为 append 查询字符串; but this feels more like a workaround.但这感觉更像是一种解决方法。

I know this is used all over the web but not sure how they achieve it.我知道这是在 web 中使用的,但不确定他们是如何实现的。 For example, I am sure I have seen things like:例如,我确信我见过这样的事情:

somedomain.com/{dataid}/main.html
somedomain.com/{dataid}/edit.html

This feels like what I am looking for and means I have a user friendly url to a given dataset.这感觉就像我正在寻找的东西,意味着我对给定的数据集有一个用户友好的 url。 Is this some sort of server side handling?这是某种服务器端处理吗? If so, what technology is in use here?如果是这样,这里使用的是什么技术?

I'd be interested in either a server side solution if that is the 'correct' way to do it and, short term, a client side solution (as I currently use neocities to serve my static pages).如果这是“正确”的方法,我会对服务器端解决方案感兴趣,短期内,我会对客户端解决方案感兴趣(因为我目前使用 neocities 为我的 static 页面提供服务)。

Clarification of requirements:要求说明:

  1. For a given browser tab, be able to load any of the 3 pages with a specific dataid .对于给定的浏览器选项卡,能够加载具有特定dataid的 3 个页面中的任何一个。
  2. Be able to have multiple tabs open, each using their own dataid .能够打开多个选项卡,每个选项卡都使用自己的dataid
  3. Any of the linked pages should continue with the current dataid .任何链接的页面都应该以当前的dataid继续。 eg if main.html links to edit.html, then if user click on the link to edit.html (either open in current tab or new tab), then edit.html should continue with the same dataid . eg if main.html links to edit.html, then if user click on the link to edit.html (either open in current tab or new tab), then edit.html should continue with the same dataid .
  4. Be able to link directly to a given dataid - eg main.html?dataset1 or similar (its OK if I need to add JS to extract the dataid before continuing).能够直接链接到给定的dataid - 例如 main.html?dataset1 或类似的(如果我需要添加 JS 以在继续之前提取dataid则可以)。

A thought that I had is, perhaps some of this maybe easier/only possible with a single page web app??我的一个想法是,也许其中一些可能更容易/只能通过单页 web 应用程序实现?

in jquery:在 jquery 中:

function Navpage(){
    windows.location("pagename.aspx?Id="+Id);
}

//the Id must be the the one you've passed in data:({"Id":Id}) under ajax call. //Id 必须是您在 ajax 调用下传入的 data:({"Id":Id})。 this function should execute onclick of a button.这个 function 应该执行一个按钮的 onclick。

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

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