micmania1 Posted October 3, 2008 Share Posted October 3, 2008 Hi, I'm trying to create a bbcode function with functionality similar to that of which is used on this site. Here's my function: function bbCode(code) { var text = ""; var e = 'message'; // ID if (document.all) { text = document.selection.createRange().text; } else { text = document.getSelection(); } if (text != '') { // text must be highlighted // Set new highlighted value if (document.all) { document.selection.createRange().text = '[' + code + ']' + text + '[/' + code + ']'; } else { var setVal = document.getSelection() = '[' + code + ']' + text + '[/' + code + ']'; } } else { document.getElementById(e).innerHTML = document.getElementById(e).innerHTML + '[' + code + '][/' + code + ']'; } } The problem i'm having is detecting where the selected text is from. For example I could highlight the footer of my website which has no relation to the bbcode function, but when the 'bold' tag is clicked, it will wrap the footer in bold tags or any text on that page which I select. Could somebody tell me how I can detect where the selected text is? Thanks for your time. Michael Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 4, 2008 Share Posted October 4, 2008 I'm sure SMF wouldn't mind you taking a look at their code, since it is Open Source. Just make sure you don't remove any copyright notices that may be present if you intend on using some of their JS. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.