0

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

qwertymk
  • 34,200
  • 28
  • 121
  • 184
  • "how do I do this?" questions get down voted. This one wasn't mine btw. – BNL Nov 28 '11 at 01:49
  • @BNL: What's the best way to do this? is not How do I do this. I presented two options and asked which one is the best – qwertymk Nov 28 '11 at 01:51

3 Answers3

2

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
  • This won't work, as he wants to use the page offline. No dynamic stuff is available... he either needs to store stuff client-side using HTML5, or put everything in the anchor part of the URL. – Brad Nov 28 '11 at 03:14
  • That's why I mentioned "he either needs to store stuff client-side using HTML5, or...". If that is what you suggest, then you should provide a basic example. – Brad Nov 28 '11 at 04:21
1

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.

Community
  • 1
  • 1
Brad
  • 159,648
  • 54
  • 349
  • 530
0

Use javascript function:

encodeURIComponent('_Hello_ *World*');
Tadej Magajna
  • 2,765
  • 1
  • 25
  • 41