Jump to content

Document.Selection


Chocolate570
 Share

Recommended Posts

So, i'm helping a person with their forum. Everything's great except for one thing: The bbcode inserting function doesn't work in firefox. I think I have discovered the problem, it's the document.selection. From what I remember a long time ago, that's an IE only method. Correct? So I need to figure out how to make the function work cross-browser. I have also learnt that document.getSelection() works cross-browser, but how to integrate it? And do you see any other problems with this code? Thank you very much.This is the function that inserts the bbcode into the post box with the attribute name set as "post".

function createlist(){  f1.post.focus(); var selected = document.selection; var srange = selected.createRange(); srange.colapse; if(srange.text=="") alert('There is no text selected to format'); else { nq=srange.text.split("\n").join("\n[*]"); srange.text="[*]" + nq; }} function LBC(func){  f1.post.focus(); var seected = document.getSelection; var srange = selected.createRange; srange.colapse; var nq=srange.text; if(srange.text=="") alert('There is no text selected to format'); else { switch(func) {case 'b':nq="[b]"+srange.text+"[/b]"; break;case "i":nq="[i]"+srange.text+"[/i]"; break;case "u":nq="[u]"+srange.text+"[/u]"; break;case "img": nq="[img="+srange.text+"]; break;case "q":nq="[QUOTE]"+srange.text+"[/QUOTE]"; break;case "c":nq="[CODE]"+srange.text+"[/code ]"; break;case "url":nq="[url=http://"+srange.text+"]"+srange.text+"[/url]"; break; } srange.text=nq;}}f1.name.focus();

Thank you very much in advance.<Chocolate570>

Link to comment
Share on other sites

i don't know much about javascript, but if im not mistaken isn't it all case sensitive?instead of

case "c":nq="[CODE]"+srange.text+"[/code ]"; break;[/code]

shouldn't it be

[code]case "c":nq="[code]"+srange.text+"[/code ]"; break;[/code]

not sure if that will help, or if it matters.

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
 Share

×
×
  • Create New...