简体   繁体   中英

Using # tag in URL to save data from Javascript

I have a site with loads of Javascript, where users input informations, which gets saved in Javascript objects on the site. I also have a working export/import from JSON - once the user fills out the form, he can "Export to JSON", and if he refreshes the page (and the form is cleared), he can "Import from JSON" and the forms get filled.

I want to also save the data into the URL , so the users can simply share the URL, and the forms will get pre-filled based on the URL content .

Closest example I was able to find is these old game calculators - http://classicdb.ch/?talent#Lsoedm0oZVx0f0xoZTMo

The information is encoded in the #Lsoedm0oZVx0f0xoZTMo and then processed and the form is filled.

How does one go about implementing this? Can I use the JSON import which I already have?

Thank you

Appending the hash to the url should not be the question but receiving and processing, right? For these javascript provides

location.hash

That way you will get the "Lsoedm0oZVx0f0xoZTMo" and do whatever you have to.

If you're asking how to make the hash that could be part of the URL. This article might help you: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding

In case you want to modify or receive the hash from URL, René's answer answered that already. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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