Results 1 to 6 of 6

Thread: Mozilla selectionStart / End

  1. #1
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default Mozilla selectionStart / End

    I'm bouncing off the walls here trying to find the solution to this problem (my first problem in a long list )

    I can successfully use selectionStart and selectionEnd when I am targetting a textarea object but for some reason firefox3 wont return these details for an IFrame?
    HTML Code:
                var selectedTexty = document.getElementById('iView').contentWindow;
                alert(selectedTexty);
                alert(selectedTexty.getSelection());
                     
                var startPos = document.getElementById('iView').selectionStart;
          
                alert(startPos);
    Returns;
    [object Window]

    then...
    asdasdasadasd asd asdas adas //my selection from within the editable iframe

    then...
    undefined //this would normally return a start position for the highlighted text when used in a textarea element but returns undefined when used with iframe?

    Thanks
    Dal
    Programmers are tools used to convert Caffeine to code

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try:
    Code:
    var startPos = document.getElementById('iView').contentWindow.selectionStart;
    alert(startPos);
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. The Following User Says Thank You to Master_script_maker For This Useful Post:

    Dal (02-22-2009)

  4. #3
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Thanks for the reply but I already tried that. After I studied the mozilla wysiwyg example I relised that I needed to select a range object and use that as the reference to getting something called startOffset which returned the correct value. This seems to work until I make the text within the iframe formatted (for example bold)

    Code:
                var selectedTexty = document.getElementById('iView').contentWindow;
                alert(selectedTexty);
                alert(selectedTexty.getSelection());
                var sel = selectedTexty.getSelection();
            
                alert(selectedTexty.setSelectionRange);
            
                var range = sel.getRangeAt(0);
                
                sel.removeAllRanges();            
    
                var startPos = range.startOffset
          
                alert(startPos);
    Any ideas why the formatting would knock out the offset value?

    Cheers
    Dal

    Edit: Actually upon further investigation it seems that it depends where the selection is and the offset comes from the inner tag if selected ie;
    offset values: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
    text: "this is normal text this is bold text"

    I'm sure I'll figure it but it would be handy to have as much information about these details as possible as I've never used these objects before. Scanned the web looking for handy reference but they all seem to have some things that work and somethings that dont then there are the three schools (ff,ie,safari) which handle these all differently (which doesnt help the learning cycle at all!)

    Cheers again
    Dal
    Last edited by Dal; 02-22-2009 at 12:29 AM.
    Programmers are tools used to convert Caffeine to code

  5. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Last edited by Master_script_maker; 02-22-2009 at 05:42 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  6. The Following User Says Thank You to Master_script_maker For This Useful Post:

    Dal (02-22-2009)

  7. #5
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Cheers, I started hitting loads of problems after I figured out all the node controls so I think I'll put this project on the back burner for now. Seems that grabbing the selected text with mozilla doesnt grab the html code behind so when I make something like a word bold and then the sentence italic the bold goes missing.

    I guess I'm put off by the fact that once I do get this thing build (wysiwyg editor), I then need to redo the whole thing for MSIE to work. I dont have that much time at the moment but I do intend to complete this project because I think I could learn alot from doing it and I'd also have something that I can embed into a cms system that belongs to me. For now I like the look of hoteditor although there are others I can use too.

    Thanks Master_script_maker
    Dal
    Programmers are tools used to convert Caffeine to code

  8. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    You're welcome. I hope you get to finish your project. If I find anything else I'll post it here.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •