qwertymk
qwertymk

Reputation: 35284

Best way to save info in hash

I have a webpage that the user inputs data into a textarea and then process and display it with some javascript. For example if the user types:

_Hello_ *World* it would do something like:

<underline>Hello</underline> <b>World</b>

Or something like that, the details aren't important. Now the user can "save" the page to make it something like site.com/page#_Hello_%20*World* and share that link with others.

My question is: Is this the best way to do this? Is there a limit on a url that I should be worried about? Should I do something like what jsfiddle does?

I would prefer not to as the site would work offline if the full text would be in the hash, and as the nature of the site is to be used offline, the user would have to first cache the jsfiddle-like hash before they could use it.

What's the best way to do this?

EDIT: Ok the example I gave is nothing similar to what I'm actually doing. I'm not cloning markdown or using underline or b tags, just wanted to illustrate what I wanted

Upvotes: 0

Views: 138

Answers (3)

tereško
tereško

Reputation: 58444

Instead of trying to save stuff in the URL, you should use the same approach that is common in pastebins: you store the data , can provide use with url, containing an unique string to identify stored document. Something like http://foo.bar/g4jg64

From URL you get state or identifiers, not the data.

Upvotes: 2

Brad
Brad

Reputation: 163430

URLs are typically limited to 2KB total, but there is no officially designated limit. It is browser-dependent.

Other than that, make sure you properly URL encode what you're putting up there, and you're fine... although I certainly would not want to deal with obnoxiously long URLs. I might suggest you also avoid tags such as <underline> and <b>, as they have been deprecated for a very, very long time.

Upvotes: 1

Tadej Magajna
Tadej Magajna

Reputation: 2963

Use javascript function:

encodeURIComponent('_Hello_ *World*');

Upvotes: 0

Related Questions