JS script for nice and SEO friendly URL

I won't explain what 'nice URL' and 'mod_rewrite' means here. I suppose that everybody can find any information needed on Google (as do I). But what did I look for with no effect was a JS script that will beautifully, effectively and with no problem transform whatever diacritic letters (either it is from czech or slovac language) to a nice and SEO friendly URL (so diacritic letters with wedges and strokes or accents will be transformed to the letters without these marks and spaces and other unconvenient marks will be replaced by dashes).

I can't say I didn't find anything. The scripts I've found either didn't transform all of diacritic letters, didn't transform any diacritic letters or were deadly robust and slow.

Also I was disappointed with the fact: page titles cantaining a space, dash and space (e.g.. "Gallery – Nature") are replaced with three dashes after being processed by all common JS scripts (so "gallery—nature").

So I took one of those scripts and changed it to handle all the czech (or slovak, or other alphabets after small update) diacritic characters and it replaces all consecutive dashes by just one dash (so the title from previous paragraph would look like  "gallery-nature").

All You need is the JS file (provided here later) and to use onkeyup and onchange events with calling of  JS method generateURL(this) in text input for title. This method is then responsible for generating of nice URL into next text input with ID "rewrite". This text input has also onchange event that calls method linkChanged() which is useful when editing the link and want to prevent it to be rewritten after the title is changed (but You can omit this event and linkChanged() method if You wish so).

Here is the HTML code example:

<input onkeyup="generateURL(this)" onchange="generateURL(this)" class="text" size="80" type="text" value="def value from php?" id="title" name="title" title="Page title" />
<input onchange="linkChanged();" class="text" size="80" type="text" value="def value from php?" id="rewrite" name="rewrite" title="Page title for URL" />

And live example:

And that' it!

JS file: url.js.

Komentáře jsou uzavřeny.