Javascript eval in window popup?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Javascript eval in window popup?

Post 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 + "');");
}
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Javascript eval in window popup?

Post 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 ;))
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tim is correct on all counts.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Ok, that makes sense, thank you. I don't need to reference it so I'll pull that part out.
Post Reply