Jump to content

text recognition


joecoolaug

Recommended Posts

I've been wondering something recently.How is it possible for text in a HTML document or user-entered textarea text to be recognized and manipulated? For example:

\\On this forum,\\this text becomes a smiley when you post it::)\\and this text becomes a link:[url=http://www.wow.com]a link[/url]

I know that this is possible with server scripting, but, since I don't have any servers, is there any way to do this with only HTML, a scripting language, and/or XML?

Link to comment
Share on other sites

for javascript do this
var str = "my text goes like this and it has a :) smily face";document.write(str.replace(':)','<img src="url to image" alt="Smile"/>'))

Okay... so that only replaces text in the variable. That will work for textareas and inputs, and that's all I plan on using it for. Just out of curiosity, though, is there any way I could apply this to use it for some text in a document?
Link to comment
Share on other sites

var str = document.body.innerHTML;document.write(str.replace(':)','<img src="url to image" alt="Smile"/>'))

It's not working. Obviously I'm doing something wrong.Here is my site.Here's the code:
<html><head><title>blank</title><script type="text/javascript">var str = document.body.innerHTML;document.write(str.replace(':)','<img src="/joecoolaug/untitled3.png" alt="Smile"/>'))</script></head><body>:)</body></html>

All right... I'm not so great with javascript. I don't understand why you have "document.write" in there. That won't just replace ":)" but will also replace all other code in the <body> tag, won't it? Wow... I'm confused, as usual :).

Link to comment
Share on other sites

that was just a simple example of course you can't just stick it anywhere and expect ti to work.do this

<html><head><title>blank</title><script type="text/javascript">		function insertSmile()	{		var str = document.body.innerHTML;		document.body.innerHTML = str.replace(':)','<img src="/joecoolaug/untitled3.png" alt="Smile"/>');	}</script></head><body onload="insertSmile()">:)</body></html>

Link to comment
Share on other sites

that was just a simple example of course you can't just stick it anywhere and expect ti to work.do this
<html><head><title>blank</title><script type="text/javascript">		function insertSmile()	{		var str = document.body.innerHTML;		document.body.innerHTML = str.replace(':)','<img src="/joecoolaug/untitled3.png" alt="Smile"/>');	}</script></head><body onload="insertSmile()">:)</body></html>

Okay... It's working now, but why does it have to be in a function?EDIT: Nevermind. I saw what you changed.
Link to comment
Share on other sites

Just a quick tip---any scripts that modify the page in any way should be either launched through onload=, or put RIGHT BEFORE the </body> end tag. :)

Link to comment
Share on other sites

Why's that. I've never heard that before :) .
One of the main reasons your original script didn't work is because it was being executed before the :) was even rendered to the screen...which means when the javascript ran it didn't find a :) cbecause it did not exist yet.By placing the script last or wrapped in a body onload event it garentees the document is fully loaded before executing the javascript.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...