SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
May 28, 2007, 19:02 #1
- 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?
-
May 28, 2007, 22:31 #2
- 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.
-
May 29, 2007, 00:58 #3
- 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.
-
May 29, 2007, 01:33 #4
- 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.
-
May 29, 2007, 09:37 #5
- Join Date
- May 2007
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 whydocument["this.idf"].style.left
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........
-
Jun 3, 2007, 04:09 #6
- 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.
-
Jun 3, 2007, 05:15 #7
- 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';
Bookmarks