Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Ajax jQuery
Hi all
 
For tabbing i have written below code
function bindTabbing(event)
{
    if (event.which || event.keyCode)
    {
        // 9 indicates TAB key.
        if ((event.which == 9) || (event.keyCode == 9))
        {
            var subject = document.getElementById(txtProgramEditor); // Get the Editor textarea control.
            if (event.srcElement == subject) // If tab is pressed in the textarea then do the action.
            {
                // Creates a range and adds the Tab equivalent character in the text range.
                subject.selection = document.selection.createRange();
                subject.selection.text = String.fromCharCode(9);
                event.returnValue = false;
            }
 
            if (subject.selectionStart || subject.selectionStart == '0')
            {
                var str = subject.value;
                var startIndex = subject.selectionStart;
                subject.value = str.substring(0, startIndex) + '    ' + str.substring(startIndex, str.length);
                subject.focus();
                subject.selectionEnd = startIndex + 4;
                return false;
            }
        }
    }
    else
    {
        return true;
    }
}
this is working fine in FireFox and IE but not working in Chrome and Safari
 
Please locate the problem done by me or suggest what to do..
 
Thanks in advance.
Posted 16-Sep-12 23:07pm
Mac123341.1K
Edited 17-Sep-12 1:53am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

createRange does not work in safari and Chrome
subject.selection = document.selection.createRange();
rather then this use
subject.selection = window.getSelection();
 
This will work in all browser and IE 9+.
 

refer these links
http://help.dottoro.com/ljrvjsfe.php[^]
http://stackoverflow.com/questions/7021497/document-selection-createrange-not-working-in-chrome-and-safari[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 293
1 Sergey Alexandrovich Kryukov 281
2 RyanDev 65
3 nv3 60
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100