Page 1 of 1

Javascript eval in window popup?

Posted: Fri Apr 14, 2006 3:33 am
by Benjamin
I'm not versed in javascript, and I found a snippet I modified a little bit for my needs. I noticed that it's using an eval statement, and a Date function. I am wondering why.

Code: Select all

function OpenWindow(pagename, pageheight, pagewidth) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + pagewidth + ",height=" + pageheight + "');");
}

Re: Javascript eval in window popup?

Posted: Fri Apr 14, 2006 6:57 am
by timvw
agtlewis wrote:I'm not versed in javascript, and I found a snippet I modified a little bit for my needs. I noticed that it's using an eval statement, and a Date function. I am wondering why.

Code: Select all

function OpenWindow(pagename, pageheight, pagewidth) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + pagewidth + ",height=" + pageheight + "');");
}
If i understand well, they want to be able to reference to the window with pageX (where X is the id)...
I don't see a reason to use the time as X though...

If no reference to the window is needed, simply call windows.open and don't assign to a variable...
If a reference is needed, use an array instead ;) pages[id] = window.open...

(PS: I just started JS so i'm not an expert and take it with a grain of salt ;))

Posted: Fri Apr 14, 2006 7:37 am
by feyd
tim is correct on all counts.

Posted: Fri Apr 14, 2006 8:07 am
by Benjamin
Ok, that makes sense, thank you. I don't need to reference it so I'll pull that part out.