Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Very very basic & crossbrowser rich-text editor
Old 12-16-2009, 06:25 PM Very very basic & crossbrowser rich-text editor
Junior Talker

Posts: 4
Name: orhun
Trades: 0
i want to make an very very basic rich-text editor, which works in all browser types.

i have the code at below.. but it only works on -8 IE browsers.
could someone help me to make this code crossbrowser..

Code:
 
<script type="text/javascript">
<!--
    function formatText (tag) {
        var selectedText = document.selection.createRange().text;
        
        if (selectedText != "") {
            var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]";
            document.selection.createRange().text = newText;
        }
    }
//-->
</script>
<form name="my_form">
    <textarea name="my_textarea"></textarea><br />
    <input type="button" value="bold" onclick="formatText ('b');" />
    <input type="button" value="italic" onclick="formatText ('i');" />
    <input type="button" value="underline" onclick="formatText ('u');" />
</form>

orhuns is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-16-2009, 06:30 PM Re: Very very basic & crossbrowser rich-text editor
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Here's one I prepared earlier.

http://www.webmaster-talk.com/javasc...tml#post772383
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-16-2009, 08:10 PM Re: Very very basic & crossbrowser rich-text editor
Junior Talker

Posts: 4
Name: orhun
Trades: 0
so, could u adapt your style to my code?

or.. how can i cahnge your code like:adding tags before/after to the selected words on text area?
orhuns is offline
Reply With Quote
View Public Profile
 
Old 12-17-2009, 06:22 AM Re: Very very basic & crossbrowser rich-text editor
Junior Talker

Posts: 4
Name: orhun
Trades: 0
i did it like this... and its working crossbrowser..
but.. it's adding tags to the before/after to all writtens in textarea... (document.getElementById('textarea'))

It must add the tags before/after to the only sellected words..

Code:
<script type="text/javascript">
<!--
function addtag(p_oObj, p_sText) {
p_oObj.value = '[' + p_sText + ']' + p_oObj.value + '[/' + p_sText + ']';
}
//-->
</script>

<button onclick="addtag(document.getElementById('textarea'),'b')">B</button><br/>
<textarea id="textarea" name="message" style="resize: vertical;" rows="12" cols="48"></textarea>

Last edited by orhuns; 12-17-2009 at 06:32 AM..
orhuns is offline
Reply With Quote
View Public Profile
 
Old 12-17-2009, 09:22 AM Re: Very very basic & crossbrowser rich-text editor
Banned

Posts: 1
Name: sdfsd
Trades: 0
i want to make an very very basic rich-text editor, which works in all browser types.
csjanm is offline
Reply With Quote
View Public Profile
 
Old 01-02-2010, 05:50 AM Re: Very very basic & crossbrowser rich-text editor
Clarksy's Avatar
Junior Talker

Posts: 3
Trades: 0
To work with the current selection you'll need to look into browser selections:

For W3C browsers (Firefox, opera, safari etc) your can use textarea.selectionStart and textarea.selectionEnd properties to determine whats selected.

For IE its a bit trickier - you need to look at the textRange object http://msdn.microsoft.com/en-us/libr...72(VS.85).aspx
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Clarksy is offline
Reply With Quote
View Public Profile Visit Clarksy's homepage!
 
Reply     « Reply to Very very basic & crossbrowser rich-text editor
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24813 seconds with 12 queries