SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: cursor issue IE

  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    stcloud
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cursor issue IE

    This works great in Firefox, but not in IE

    Problem I am having is after I click link to insert bbcode and then while cursor is in between the 2 tags I click to insert bbcode and the new bbcode end up on the end next to the first ones I added and not between the 2 I first added.

    Like I said in Firefox it works like a charm.

    Please can someone figure this out for me.

    I know theres a way to fix this because it works the way I want in Vbulltin in IE.

    I need help please. Been googling for days now.

    HTML Code:
    <html>
    <head>
    <!-- ... -->
    <script language="JavaScript" type="text/javascript">
    <!--
    var clientInfo = navigator.userAgent.toLowerCase();
    var isIE = ( clientInfo.indexOf("msie") != -1 );
    var isWin = ( (clientInfo.indexOf("win")!=-1) || (clientInfo.indexOf("16bit") != -1) );
    
    function createBBtag( openerTag , closerTag , areaId ) {
    	if(isIE && isWin) {
    		createBBtag_IE( openerTag , closerTag , areaId );
    	}
    	else {
    		createBBtag_nav( openerTag , closerTag , areaId );
    	}
    	return;
    }
    
    function createBBtag_IE( openerTag , closerTag , areaId ) {
    	var txtArea = document.getElementById( areaId );
    	var aSelection = document.selection.createRange().text;
    	var range = txtArea.createTextRange();
    
    	if(aSelection) {
    		document.selection.createRange().text = openerTag + aSelection + closerTag;
    		txtArea.focus();
    		range.move('textedit');
    		range.select();
    	}
    	else {
    		var oldStringLength = range.text.length + openerTag.length;
    		txtArea.value += openerTag + closerTag;
    		txtArea.focus();
    		range.move('character',oldStringLength);
    		range.collapse(false);
    		range.select();
    	}
    	return;
    }
    
    function createBBtag_nav( openerTag , closerTag , areaId ) {
    	var txtArea = document.getElementById( areaId );
    	if (txtArea.selectionEnd && (txtArea.selectionEnd - txtArea.selectionStart > 0) ) {
    		var preString = (txtArea.value).substring(0,txtArea.selectionStart);
    		var newString = openerTag + (txtArea.value).substring(txtArea.selectionStart,txtArea.selectionEnd) + closerTag;
    		var postString = (txtArea.value).substring(txtArea.selectionEnd);
    		txtArea.value = preString + newString + postString;
    		txtArea.focus();
    	}
    	else {
    		var offset = txtArea.selectionStart;
    		var preString = (txtArea.value).substring(0,offset);
    		var newString = openerTag + closerTag;
    		var postString = (txtArea.value).substring(offset);
    		txtArea.value = preString + newString + postString;
    		txtArea.selectionStart = offset + openerTag.length;
    		txtArea.selectionEnd = offset + openerTag.length;
    		txtArea.focus();
    	}
    	return;
    }
    //-->
    </script>
    </head>
    <body>
    <!-- ... -->
    <form onSubmit="return false;">
    	<textarea id="txtA"></textarea>
    </form>
    <a href="javascript:createBBtag('[bold]','[/bold]','txtA')"><strong>B</strong></a>
    <!-- ... -->
    </body>
    --------------------------------------------------------------------------------
    Last edited by cdc08x : 09-25-2005 at 12:32 AM.  
               
    

  2. #2
    SitePoint Member
    Join Date
    Jan 2005
    Location
    stcloud
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cursor issue IE

    Here is what is happening if this helps more.

    HTML Code:
    {p}cursor{/p}
    Click link again and should be like this.
    {b}{s}{/s}{/b}
    Instead it ends up like this.
    {b}{/b}{s}{/s}
    
    But only in IE
    Last edited by slim05; Apr 6, 2008 at 20:38. Reason: was not showing up cause of tags

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    stcloud
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In IE the below part works if text is selected and works the way it should.
    HTML Code:
    	if(aSelection) {
    		document.selection.createRange().text = openerTag + aSelection + closerTag;
    		txtArea.focus();
    		range.move('textedit');
    		range.select();
    	}
    This part does not in IE

    HTML Code:
    	else {
    		var oldStringLength = range.text.length + openerTag.length;
    		txtArea.value += openerTag + closerTag;
    		txtArea.focus();
    		range.move('character',oldStringLength);
    		range.collapse(false);
    		range.select();
    	}
    Now isn't there a way to fake it so that it acts like it selected something so that the new tags get placed where they should ?

  4. #4
    SitePoint Member
    Join Date
    Jan 2005
    Location
    stcloud
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use range.moveStart(...) and range.moveEnd(...) to set selection in a correct position


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
  •