joecoolaug Posted August 21, 2006 Share Posted August 21, 2006 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 More sharing options...
Cronthenoob Posted August 21, 2006 Share Posted August 21, 2006 You could probably do it with javascript. Just tell it to find anywhere : and ) are together and replace it with an image. Link to comment Share on other sites More sharing options...
Little Goat Posted August 21, 2006 Share Posted August 21, 2006 actually, it is done with php. here is a post that deals with the bbcode, and you can o something similar for smileys. Link to comment Share on other sites More sharing options...
Cronthenoob Posted August 21, 2006 Share Posted August 21, 2006 actually, it is done with php. here is a post that deals with the bbcode, and you can o something similar for smileys.He said he doesnt have access to PHP or any server side scripting. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 21, 2006 Share Posted August 21, 2006 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"/>')) Link to comment Share on other sites More sharing options...
Little Goat Posted August 21, 2006 Share Posted August 21, 2006 He said he doesnt have access to PHP or any server side scripting.oh, sorry. I guess I didn't read your post closely enough. Link to comment Share on other sites More sharing options...
joecoolaug Posted August 22, 2006 Author Share Posted August 22, 2006 for javascript do thisvar 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 More sharing options...
aspnetguy Posted August 22, 2006 Share Posted August 22, 2006 var str = document.body.innerHTML;document.write(str.replace(':)','<img src="url to image" alt="Smile"/>')) Link to comment Share on other sites More sharing options...
joecoolaug Posted August 22, 2006 Author Share Posted August 22, 2006 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 More sharing options...
aspnetguy Posted August 22, 2006 Share Posted August 22, 2006 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 More sharing options...
dcole.ath.cx Posted August 22, 2006 Share Posted August 22, 2006 nvm, aspnetguy got to it first... only because I had to read all the posts first. ... there is no delete button, umm. Link to comment Share on other sites More sharing options...
joecoolaug Posted August 22, 2006 Author Share Posted August 22, 2006 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 More sharing options...
Chocolate570 Posted August 23, 2006 Share Posted August 23, 2006 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 More sharing options...
joecoolaug Posted August 24, 2006 Author Share Posted August 24, 2006 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. Why's that. I've never heard that before . Link to comment Share on other sites More sharing options...
aspnetguy Posted August 24, 2006 Share Posted August 24, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now