JavaScript code works in IE but not in firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tweetz
    New Member
    • Jun 2010
    • 19

    JavaScript code works in IE but not in firefox

    Code:
    function storePosition () {
    	
     
      
      	if(g_state.aName == 'TABLE' || g_state.aName == 'IMG')
        	return;
    
    	var sel = this.selection;
    	if (!sel) {
    		if(!is_browserName_IE)
    		{
    			sel = document.getElementById("myEditor").contentDocument.getSelection();
    			rng=sel;
    		}
    		else
    		{
    			sel = document.frames["myEditor"].document.selection;
    			rng = sel.createRange();
    		}
    	}
    	    
    	
    	  
    	if (!rng) {
    		return;
    	}
    
    	if (caretPos) {
    		prevPos = caretPos;	
    	}
     
    	// Special case when the selection is a div:
    	if(rng.length) {
    		// This is a controlRange
    	 	var oElm = rng(0);
    	 	g_state.clickedElement = oElm;
    	 }
    	 else {
    		caretPos = rng.duplicate();	
    	 	g_state.clickedElement = caretPos.parentElement();
    	 	
    	 }
        return;
    Last edited by Dormilich; Jun 3 '10, 10:00 PM. Reason: changed thread title to reflect the correct programming language
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    are there any messages in the Error Console?

    Comment

    • tweetz
      New Member
      • Jun 2010
      • 19

      #3
      Originally posted by Dormilich
      are there any messages in the Error Console?
      yeah...it just came "rng is not a function" in error console.Plz help me

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        line #35: you call rng() as a function, but it’s a Selection object. maybe you mean rng[0]?
        Last edited by Dormilich; Jun 3 '10, 12:59 PM. Reason: corrected Object type

        Comment

        • tweetz
          New Member
          • Jun 2010
          • 19

          #5
          Originally posted by Dormilich
          line #35: you call rng() as a function, but it’s a Range object. maybe you mean rng[0]?
          yeah the error is showing @line 35( var oElm = rng(0);)and error msg is rng is not a function

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            did you apply the fix?

            Comment

            • tweetz
              New Member
              • Jun 2010
              • 19

              #7
              Originally posted by Dormilich
              did you apply the fix?
              Nop...Just struggling with this.I am new to this.So I hav no idea.Also I am gettin 1 more error in another js file.I have to fix these two errors..Please help me fixing this.Tomorrow is a deadline

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                maybe you mean rng[0]?
                this fix!

                Comment

                • tweetz
                  New Member
                  • Jun 2010
                  • 19

                  #9
                  Originally posted by Dormilich
                  this fix!
                  ok..thanks a lot..also I hav 1 more error @ the first line and the error msg is text is undefined.Pleas e help me in this too


                  if(text.indexOf ("<TABLE") >=0 || text.indexOf("< table") >=0)
                  return 'table';

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    well, it’s just as the message says, the text variable is neither a string literal, nor object. thus you can’t apply the methods to it.

                    Comment

                    • tweetz
                      New Member
                      • Jun 2010
                      • 19

                      #11
                      Originally posted by Dormilich
                      well, it’s just as the message says, the text variable is neither a string literal, nor object. thus you can’t apply the methods to it.
                      what else can I do? Can't fix this?plz provide me a solution

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        provide me with a code first ;)

                        Comment

                        • tweetz
                          New Member
                          • Jun 2010
                          • 19

                          #13
                          Originally posted by Dormilich
                          provide me with a code first ;)
                          this is the function.If u want me to send the entire code den I will send it..Thanks



                          Code:
                          function hasTagsInText(text)
                          {
                          	
                          	if(text.indexOf("<TABLE") >=0 || text.indexOf("<table") >=0)
                                  return 'table';
                                  
                              if(text.indexOf("<TD") >=0 || text.indexOf("<td") >=0)
                                  return 'column';	
                                  
                              if(text.indexOf("<IMG") >=0 || text.indexOf("<img") >=0)
                                  return 'image';
                              
                          	if(text.indexOf("<H2") >=0 || text.indexOf("<h2") >=0)
                                  return 'h2';
                          		       
                              if(text.indexOf("<DIV") >=0 || text.indexOf("<div") >=0)
                                  return 'div';
                                      
                          	if(text.indexOf("<A") >=0 || text.indexOf("<a") >=0)
                                  return 'link';   
                          		
                              if(text.indexOf("<FORM") >=0 || text.indexOf("<form") >=0)
                                  return 'form';
                          		
                          	if(text.indexOf("<P>") >=0 || text.indexOf("<p>") >=0)
                                  return 'invisible paragraph-mark';
                          		
                              if(text.indexOf("<BR>") >=0 || text.indexOf("<br>") >=0)
                                  return 'invisible new-line-mark';
                          
                          	return '';
                          }
                          Last edited by Dormilich; Jun 3 '10, 01:16 PM. Reason: Please use [code] tags when posting code

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            how do you call the function?

                            Comment

                            • tweetz
                              New Member
                              • Jun 2010
                              • 19

                              #15
                              Originally posted by Dormilich
                              how do you call the function?
                              In Java I dont hav much idea..In C/C++ we do call function by name or referrence

                              Comment

                              Working...