IE: "Expected Identifier" error :(

H

harshadanarvekar

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:
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.p
opTop
}


};


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?
 
A

ASM

(e-mail address removed) a écrit :
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:
if(ie){

window.alert("here!");

this.idf.style.left=this.popLeft
+document.body.scrollLeft;[/QUOTE]

perhaps :
document.all[this.idf].style.left = ...
[QUOTE]
this.idf.style.top=this.popTop;

}

else if (ns4){

document.(this.idf).pageX=this.popLeft
+window.pageXOffset;[/QUOTE]

perhaps :
document.layers[this.idf].pageX = ...
or :
document.this.idf.pageX = ...
 
R

RobG

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:
function PopUp(idf,stepX,stepY,speed){

this.idf=idf;[/QUOTE]

What is idf?  Is it an ID or a reference to a DOM element?  Given the
issues you have later, why not resolve it right here and make it a
reference to a DOM element?  The best way to do that depends on how
you are calling PopUp().

[QUOTE]
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;}[/QUOTE]

What is xon?  Consider:

if ( !xon ){ this.popLeft -= this.popXStep;}

[QUOTE]
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){[/QUOTE]

Browser sniffing is *never* a good idea.  Use feature detection.

[QUOTE]
window.alert("here!");
this.idf.style.left=this.popLeft[/QUOTE]

Presumably this.idf is an ID (a string) that you are expecting to be
resolved to a DOM object reference.  Strings don't have a style
property (unless you've extended the built-in String object).  A much
more sensible idea is to use feature detection along the lines of:

var domElement;
if (document.getElementById) {
domElement = document.getElementById(this.idf);
} else if (document.all){
domElement = document.all[this.idf];
} else if (document.layers){
domElement = document.layers[this.idf];
}

or similar strategy.  You might create your own 'getElement' function
that is initialised onload and subsequently uses the appropriate
method.

Learn to use and deploy feature detection, it will save you many hours
of frustration.  There is an example you might find useful here:

<URL: http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html >
 
S

scripts.contact

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

replace all "document.(this.idf)" with "document[this.idf]"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top