473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2714
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

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

Similar topics

5
by: Rick | last post by:
I wrote the following code as part of a page where users can reorder a list of items by highlighting an item in a list box and clicking an "up" or "down" button to move the items around. The code...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
6
by: craigbeanhead | last post by:
Hi, I'm teaching myself C from K&R2. I've come across something that I really don't understand. When I try to compile the following code (in VC++7), I get an "undeclared identifier" error. When...
3
by: rdi | last post by:
The import statements weren't copy/pasted, but everything INSIDE the class WAS copy pasted from the help file. Starting with the myMail.From line and going down to the SmtpMail.Send line, EVERY line...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
2
by: jman | last post by:
i'm getting an "object expected" error in ie - not ff. in the BODY onload attribute i call a function that's loaded from an external file. i've narrowed the error down to the fact it cannot...
2
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%=...
9
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.