469,927 Members | 1,926 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

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" .
Expand|Select|Wrap|Line Numbers
  1.  
  2.   function PopUp(idf,stepX,stepY,speed){
  3.  
  4.     this.idf=idf;
  5.     this.popXStep=stepX;
  6.     this.popYStep=stepY;
  7.     this.popSpeed=speed;
  8.     this.popLeft=0;
  9.     this.popTop=0;
  10. };
  11.  
  12.     PopUp.prototype.relocX=function() {
  13.      if(xon==0){this.popLeft=this.popLeft-this.popXStep;}
  14.     else{this.popLeft=this.popLeft+this.popXStep;}
  15.  
  16.     if(this.popLeft<0){xon=1;this.popLeft=0;}
  17.     if(this.popLeft>=(chX-ohX)){xon=0;this.popLeft=(chX-ohX);}
  18.     if(ie){
  19. window.alert("here!");
  20.         this.idf.style.left=this.popLeft+document.body.scrollLeft;
  21.         this.idf.style.top=this.popTop;
  22.     }
  23.     else if (ns4){
  24.         document.(this.idf).pageX=this.popLeft+window.pageXOffset;
  25.         document.(this.idf).pageY=this.popTop;
  26.     }
  27.     else if (ns6){
  28.         document.getElementById(this.idf).style.left=this.popLeft+window.pageXOffset
  29.         document.getElementById(this.idf).style.top=this.popTop
  30.     }
  31.  
  32. };

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?
May 29 '07 #1
8 2541
mrhoo
428 256MB
IE does not understand the pageX or pageX offset property
May 29 '07 #2
IE does not understand the pageX or pageX offset property
Yeah, well but the pageX and pageY are used for NS4, not IE, please notice the If--else blocks. I forgot to mention that I have already detected the browser versions. :)
May 29 '07 #3
acoder
16,027 Expert Mod 8TB
See the compatibility tables for different browsers for the mouse position.

It might also help to read the Find Position page.

As far as browser sniffing is concerned, that's bad practice. Use object detection instead - see link
May 29 '07 #4
Thanks links acoder. I did try following:

Expand|Select|Wrap|Line Numbers
  1. if(ie){
  2.  
  3.         document.this.idf["style.left"] = this.popLeft + document.body.scrollLeft;
  4.         document.this.idf["style.top"]=this.popTop;
  5.     }
and also

Expand|Select|Wrap|Line Numbers
  1. if(ie){
  2.  
  3.        document["this.idf"].style.left = this.popLeft + document.body.scrollLeft;
  4.        document["this.idf"].style.top = this.popTop;
  5.     }
This time, IE showed no error, but did not behave as intended also.
THe two pop ups move n FF and NS8, but not in IE6. When I debugged with
.NET, I found out that "style" was undefined!
Then finally, I went back to basics:

Expand|Select|Wrap|Line Numbers
  1. if(ie){
  2.         document.getElementById(this.idf).style.left=this.popLeft+document.body.scrollLeft;
  3.         document.getElementById(this.idf).style.top=this.popTop+document.body.scrollTop;
  4.     }
  5.     else if (ns6){
  6.         document.getElementById(this.idf).style.left=this.popLeft+window.pageXOffset
  7.         document.getElementById(this.idf).style.top=this.popTop+window.pageYOffset
  8.     }

Now it works fine in NS8,IE6 and FF2!! 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........
anyways, problem is solved. :)
May 29 '07 #5
acoder
16,027 Expert Mod 8TB
Unfortunately, we have to live with that when programming in Javascript.

Browser vendors sometimes add their own proprietary properties or just plainly do not follow the standards. Sometimes they make an attempt but fail. To top it all, Microsoft is the worst culprit and their browsers also happen to be the most popular.

Anyway, glad you got your problem solved even though I may not entirely agree with the coding.
May 29 '07 #6
Yip, Microsoft seems to be the biggest culprit, their Corporate strategies have always overshadowed their Softwares (non-standard implementations, borrowing syntaxes (c# vs Java) etc.). Anyways.
I may not entirely agree with the coding.
???
Can you suggest a better way? eg. using Object Detection?
May 29 '07 #7
acoder
16,027 Expert Mod 8TB
Can you suggest a better way? eg. using Object Detection?
It's not that difficult. Read the article on Object Detection which I linked to earlier.

Basically, replace if(ie), if(ns), etc. with detection of objects. So your code will be very similar - just that it will detect objects rather than browsers. This will make it future-proof. Many browser-sniffing programs/code fell apart with the introduction of IE7, because the code was checking for IE6, IE5, etc.

So, in your code, for example, you check for pageXOffset. IE doesn't support it, so it executes the second code block instead. If future versions of IE do support it (I'm not sure about IE7), your code doesn't break.
May 30 '07 #8
It's not that difficult. Read the article on Object Detection which I linked to earlier.

Basically, replace if(ie), if(ns), etc. with detection of objects. So your code will be very similar - just that it will detect objects rather than browsers. This will make it future-proof. Many browser-sniffing programs/code fell apart with the introduction of IE7, because the code was checking for IE6, IE5, etc.

So, in your code, for example, you check for pageXOffset. IE doesn't support it, so it executes the second code block instead. If future versions of IE do support it (I'm not sure about IE7), your code doesn't break.

Thanks acoder. I will try that. It sounds much better than browser detection.
May 30 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Jon | last post: by
2 posts views Thread by jman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.