webdad3
webdad3

Reputation: 9080

javascript eval issue

I have a function that is parsing xml which contains javascript function calls. An example of this is:

eval(getElementText(PropValue[0])); 

getElementText(PropValue[0] = top.hidePopWin()

I have followed this call up to the hidePopWin function and watched it complete from the top of the function to the bottom of the function.

Everything looks in order however I get this pesky error in Firefox: top is null As you have probably guessed hidePopWin closes the popup window that is currently displayed.

So, hidePopWin is called and it goes through just fine (in fact the popup does in fact close), but after that is the problem. It doesn't go to the next step. I get the top is null message in Firefox (firebug) and it just stops.

The only other thing I need to mention is that this whole process starts on a double click event (legacy code). There is also a single click event that fires as well. At first I thought maybe that was the issue, however, I took out the reference to the onclick event and I still get the same message.

So I'm thinking that it has something to do with the eval statement. Just for more information I am placing a console.log("1") above the eval statement and a console.log("2") below the eval. The "1" prints, the "2" does not.

Does anyone have any ideas as to what might be the issue?

Update:

 if(getElementText(PropValue[0]) == "top.hidePopWin();"){
      console.log('here');
      top.hidePopWin();
      console.log('end');
 }else{
      console.log(getElementText(PropValue[0]));
       eval(getElementText(PropValue[0]));
 }

OK I tried the above... I see the "here" statement, but it still says top is null. The "end" statement never prints. When I click on the top is null in FF it highlights the eval statement??? So I don't know what the heck is going on.

Upvotes: 0

Views: 251

Answers (3)

webdad3
webdad3

Reputation: 9080

OK... This may not be the best way to go, but I did finally get it to work. Per the suggestion to change the code to run top.hidePopWin(). I tried those suggestions however I was still getting the top is null issue.

In desperation I took out the "top." and now it works. So I'm guessing there was not a "top" variable (wierd notation in my opinion).

So now I'm capturing if the string is equaling "top.hidePopWin()" and then instead of calling the eval I'm just calling the function hidePopWin();

Seems to work. Let me know if there is another way of going about this.

Upvotes: 0

psr
psr

Reputation: 2900

is 'top' visible in that scope if you breakpoint in FF (on the console.log('here') line? It's sounding like there is no such variable (I don't know why the popup closes though).

Upvotes: 1

psr
psr

Reputation: 2900

no, but could you change the code to directly execute the code outside eval and test?

So, change, eval(getElementText(PropValue[0])); to top.hidePopWin();

see if you get the same error.

Upvotes: 2

Related Questions