nikomanek
asked on
Javascript eval method does not work in Firefox
I have an old piece of code in a website which is called after a onMouseOver event. It works flawless in IE (all newer versions),Chrome and Safari but not in Firefox.
The eval() method does not work and therefore in Firefox "Tooltip" is always undefined.
(always returns "undefined" in Firefox)
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
The eval() method does not work and therefore in Firefox "Tooltip" is always undefined.
(always returns "undefined" in Firefox)
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltip.visibility = "hidden"; }
else {
Ctl-Shift-J will bring up the Error Console which should tell you why it's not working.
The demo code on http://www.w3schools.com/jsref/jsref_eval.asp works in Firefox 7.
ASKER
Yes, thats how I found out that it always returns "undefined".
Tooltip.visibility is undefined
[Break On This Error] var Stan = Tooltip.visibility ;
Tooltip.visibility is undefined since var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
always returns undefined. in IE Tooltip is defined with the correct element
Tooltip.visibility is undefined
[Break On This Error] var Stan = Tooltip.visibility ;
Tooltip.visibility is undefined since var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
always returns undefined. in IE Tooltip is defined with the correct element
You might be leaving out a step. This page http://www.w3schools.com/jsref/prop_style_visibility.asp says it should be:
Tooltip.style.visibility
??
Tooltip.style.visibility
??
ASKER
Below is the complete code (as said, works in all browsers but FF)
var Nowa = 0;
var NE4 = 0;
var IE4 = 0;
var browser = ((navigator.appName)+(parseInt(navigator.appVersion)));
if (parseInt(navigator.appVersion) >= 10){ Nowa = 1; }
else
if (browser == "Netscape4" || browser == "Netscape5") { NE4 = 1;} else {IE4 = 1;}
if (NE4 || IE4 || Nowa)
{
var ObiektDokumentu = (NE4) ? 'document' : 'getElementById('*')';
var WlasciwoscStylu = (NE4) ? '':'.style';
}
function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltip.visibility = "hidden"; }
else {
if (NE4)
{
gora = eval (myevent.pageY +12);
lewo = eval (myevent.pageX -250);
}
if (IE4)
{
gora = eval (event.y +12);
lewo = eval (event.x -250);
}
if (lewo < 2) { lewo = 2 ;}
Tooltip.top = gora;
Tooltip.left = lewo;
Tooltip.visibility = "visible";
}
}
}
ASKER
Same result with "style"
Tooltip is undefined
[Break On This Error] var Stan = Tooltip.style.visibility ;
Tooltip is undefined
[Break On This Error] var Stan = Tooltip.style.visibility ;
Before the 'eval', put an 'alert' or document.write with "ObiektDokumentu + '.' + element + WlasciwoscStylu" to see what is there.
what about :
function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltiiiiiiiip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltiiiiiiiip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltiiiiiiiip.visibility = "hidden"; }
else {
function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltiiiiiiiip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltiiiiiiiip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltiiiiiiiip.visibility = "hidden"; }
else {
ASKER
event is not defined
[Break On This Error] gora = eval (event.y +12);
tooltip.js (line 30)
[Break On This Error] gora = eval (event.y +12);
tooltip.js (line 30)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
// Better to test for functionality rather than browser:
//
var ObiektDokumentu = document.getElementById ? "document.getElementById(*)" : "document";
//
// etc.