Thursday, April 24, 2008

How to title your pop-up window in javascript

I was recently asked by a colleague to help in a requirement with javascript.
She wants to have a popup window with a title on it. Normally it will have the url of the window as title.
The below is an example to get a title as we want.

function popitup2()
{
newwindow2=window.open('','name','height=200,width=150,resizable=1');
var tmp = newwindow2.document;
tmp.write('<--html-><--head-><--title->popup<--/--title->');
tmp.write('<--/head-><--body-><--p->this is once again a popup.<--/p->');
tmp.write('<--/body-><--/html->'); tmp.close();
}

This resolved her problem. Thanks to Kyle Varga

1 comment:

  1. Here's an even simpler way, especially when you have other HTML content in the pop up window.

    function popitup2()
    {
    newwindow2=window.open('','name','height=200,width=150,resizable=1');
    newwindow2.document.title='Test Window';
    }

    ReplyDelete