Ajax JavaScript CSS HTML 5 Gecko XUL Forum

Opening a new window in JavaScript

To display dynamically data, we can create an iframe, or open a new windows.

Properties of window creation

These attributes are assigned when creating the window. They value yes or no according to the state enabled or not.

A demonstration of window creation is provided in the appendix.

Methods

Creating a window, demo

Demonstration of the open method of the window HTML object.
Select the properties of the window to define and click on the open button. The code for the option will be displayed below the form.

In this demo, a page is loaded but its content is replaced by the following command:

win.document.write("Hello!");

Without this command, the windows does not remain displayed under IE7. You have to adapt the code as you need.

Toolbar Menubar Scrollbars Statusbar Resizable Directories

Width Height

URL


Code

function yesno(arg)
{
  if(arg) return "yes";
  return "no";
}

function demo()
{
  var t = document.myform.checktool.checked;
  var m = document.myform.checkmenu.checked;
  var s = document.myform.checkscroll.checked;
  var u = document.myform.checkstatus.checked;
  var r = document.myform.checkresize.checked;
  var d = document.myform.checkdir.checked;
  var w = document.myform.wwidth.value;
  var h = document.myform.wheight.value;
  var options = "location=yes,toolbar=" + 
          yesno(t) + 
          ",menubar=" + yesno(m) + 
          ",scrollbars=" + yesno(s) + 
         ",statusbar=" + yesno(u) +
         ",resizable=" + yesno(r) +
         ",directories=" + yesno(d) +
         ",width=" + w +
         ",height=" + h;

  var url = "window-demo.php";
  var myname = "mywindow";
  document.getElementById("storage").innerHTML = options;
  var win = window.open(url, myname, options);
  win.document.write("Hello!");	
}
© 2008-2011 Xul.fr