SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE: "Expected Identifier" error :(

    Hi Everyone,
    Here is a part of javascript code that works well in FF2 but shows above error in IE6 and error "missing name after . operator" in NS8.
    Code JavaScript:
     


    Code:
          function PopUp(idf,stepX,stepY,speed){       
       
              this.idf=idf;
       
              this.popXStep=stepX;
       
              this.popYStep=stepY;
       
              this.popSpeed=speed;
       
              this.popLeft=0;
       
              this.popTop=0;
       
          };
                PopUp.prototype.relocX=function() {
      
               if(xon==0){this.popLeft=this.popLeft-this.popXStep;}
    
              else{this.popLeft=this.popLeft+this.popXStep;}
      
             
      
              if(this.popLeft<0){xon=1;this.popLeft=0;}
      
              if(this.popLeft>=(chX-ohX)){xon=0;this.popLeft=(chX-ohX);}
      
      
            if(ie){
      
          window.alert("here!");
      
                  this.idf.style.left=this.popLeft+document.body.scrollLeft;
      
                  this.idf.style.top=this.popTop;
      
              }
      
              else if (ns4){
      
                  document.(this.idf).pageX=this.popLeft+window.pageXOffset;
      
                  document.(this.idf).pageY=this.popTop;
      
              }
      
              else if (ns6){
      
                  document.getElementById(this.idf).style.left=this.popLeft+window.pageXOffset
      
                  document.getElementById(this.idf).style.top=this.popTop
      
              } 
             
    
          };

    Here is the error copied from NS JS Console:
    Error: missing name after . operator
    Source File: file:///C:/templates/test.html
    Line: 105, Column: 17
    Source Code:
    document.(this.idf).pageX=this.popLeft+window.page XOffset;


    Well it's not because of a reserved word use. Its an addition in my project,
    I am generating a no. of pop ups on one page. Deadline is in 10 hrs! Can someone please help?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is not valid. Why are you writing code for NS4? Are you really testing in it?
    Code:
    document.(this.idf).pageX
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for comment Kravvitz.
    I use NS4 just for the study purpose, just to have options for testing. I do test the code in NS4.
    Well I have already changed the code as follows:
    if(ie){
    this.popLeft = parseInt(this.idf.["style.left"]);
    this.popTop = parseInt(this.idf.["style.top"]);
    }
    else if (ns4){
    this.popLeft=parseInt(document["this.idf.pageX"]);
    this.popTop=parseInt(document["this.idf.pageY"]);
    }

    Now this works fine in NS8, IE does not show any error, but does not work as expected either. I am moving two popups around the page, popups move in FF and NS, but not in IE.
    When I used .NET for debugging, I found out that parseInt(this.idf["style.left"]) is NAN because style.left is undefined! I cant figure out the correct syntax. Any help will be appreciated.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow. Very few people still test in NS4 because it's so old and incompatible with things and so few people still use it.

    The style object/property of elements only reflects what is set in one of its properties or the style attribute of that element. To see the computed values of the properties, you need to use another method.
    http://www.quirksmode.org/dom/getstyles.html
    http://www.robertnyman.com/2006/04/2...of-an-element/
    http://www.codehouse.com/javascript/...current_style/
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Got the solution...

    Thanks Kravvitz, for the links.
    Well I finally went back to basics, the following code works in FF2,IE6 as well as NS8:

    Code:
    if(ie){
            document.getElementById(this.idf).style.left=this.popLeft+document.body.scrollLeft;
            document.getElementById(this.idf).style.top=this.popTop+document.body.scrollTop;
        }
        else if (ns6){
            document.getElementById(this.idf).style.left=this.popLeft+window.pageXOffset
            document.getElementById(this.idf).style.top=this.popTop+window.pageYOffset
        }

    and so I was able to sleep like a innocent kid who has just finished his exams.........
    But I still dont know why
    document["this.idf"].style.left
    did not work. Why there are so many compatibility problems? I am new to javascrip, I had been programming all my days with Java and VB/VC.
    I have already used Prototype for one of my projects but because, its JS file was 57KB and I could use additional 30Kb of prototype. Hushshsh........

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome.

    There are so many compatibility problems because different browsers added their own objects and properties to the language. It took a while for things to be standardized and still not everything has been. The standards that exist are ECMAScript and the DOM.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Also, you shouldn't be detecting browsers, you should be detecting whether the current browser supports whatever it is you want to use:
    Code javascript:
    var w = window.pageXOffset || document.body.scrollLeft;
    var h = window.pageYOffset || document.body.scrollTop;
    document.getElementById(this.idf).style.left=this.popLeft+w+'px';
    document.getElementById(this.idf).style.top=this.popTop+h+'px';
    I also added 'px' there because I think w and h would be integers without the units.


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
  •