View Full Version : window on the fly

11-29-2012, 02:43 PM

I want to create a new window, from within a function, with some features.
But in the new page a design here, i must call the function confirm(). My code doesn't do anything and i really have no idea if is correct.

This is it:

<script type="text/javascript">
var wind;
function noua()
wind=window.open("","Fereastra noua", "left=50,top=50,width=600,height=500,toolbar=no,scrollbars=no,resizable=no");
wind.document.write("<html><head><title>Fereastra noua</title></head><body>");
wind.document.write("<p>Screen Coordinates:<br>");
wind.document.write("ScreenX: "+wind.screenX+"<br>");
wind.document.write("ScreenY: "+wind.screenY+"</p>");
wind.document.write("<p>Browser Details:<br>");
wind.document.write("Browser name: "+navigator.appName+"<br>");
wind.document.write("Browser version: "+parseFloat(navigator.appVersion)+"<br>");
wind.document.write("Platform: "+navigator.platform+"</p>");
wind.document.write("<div><input type='button' id='b' value='Esti sigur?' onclick='confirmare()'></div>");

function confirmare()
var r=confirm("alege");


11-29-2012, 02:55 PM
It's because confirmare is in the parent window, not the child window.

You can either include the function in the child window, or access the function in the parent window by using "window.opener.confirmare()".

11-29-2012, 03:13 PM
Thank you very much. Now it works.

11-29-2012, 03:36 PM
Although, i would have one more question. How could i include the function in the child window and open there a new web page?

11-29-2012, 03:47 PM
Add the function to the wind.document.write would be one way. But document.write is ancient and shouldn't be used, really.

Best to create another document with all the code in place, then call that file in the window.open command. IE "window.open('document.html','Fereastra noua',' attributes')".

11-29-2012, 05:49 PM
Well yeah, but then screenX and screenY won't have the same values if i write the code in a new document.

11-29-2012, 06:22 PM
Instead of wind.screenX from the parent, have you tried window.screenX in the child?

11-29-2012, 06:24 PM
Don't forget to remove the debugging alert() statements before your page goes live.