PDA

View Full Version : Pop-up window title?



derek barnstorm
01-24-2007, 09:44 PM
Hi,

I am using the following script to open a pop-up window:



<head>
<script>
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=270,height=110,left = 595,top = 325');");
}
// End -->
</script>
</head>

<body>
<a href="javascript:popUp('popup.html')"><b>Open Window</b></a>
</body>

Is it possible to add a title to the page in the browser? And if so, how?

For example, here:

http://spacerockcity.com/stuff/popup.jpg

Thanks,

Des.

Twey
01-24-2007, 10:14 PM
Ugh.
<script>The type attribute is required.
<!-- BeginThis has been unnecessary for a long time: while there are some browsers left that don't do Javascript, they all at least know enough to ignore it.
day = new Date();day hasn't been declared, so you're unnecessarily making it global; the same applies to id. It also seems kind of pointless to store the window if you're not going to do anything with it.
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=270,height=110,left = 595,top = 325');");eval() is very ugly and very rarely required. Here, for example, one would use an array. If, for some reason that doesn't apply here, you really wished to create individual global variables, you could access them as window[nameOfVariable]; for example,
window["page" + id] = window.open( ... );
<script type="text/javascript">
var pages = [];
function popUp(URL) {
var opts =
"toolbar=0," +
"scrollbars=0," +
"statusbar=0," +
"menubar=0," +
"resizable=0," +
"width=270," +
"height=110," +
"left=595," +
"top=325";

pages.push(
window.open(URL,
"win" + pages.length,
opts
)
);
}
</script>You can change the title of the window with document.title, at least if the page is on the same domain.
var pages = [];
function popUp(url, title) {
var opts =
"toolbar=0," +
"scrollbars=0," +
"statusbar=0," +
"menubar=0," +
"resizable=0," +
"width=270," +
"height=110," +
"left=595," +
"top=325";

pages.push(
window.open(url,
"win" + pages.length,
opts
)
);
pages[pages.length - 1].document.title = title;
}

derek barnstorm
01-24-2007, 10:36 PM
Thanks very much for your reply and the information.
My domain name is actually being directed to a folder on my server, so perhaps it's not possible.

Thanks again for your help.

Des.

Sorry, it works fine. I made a silly mistake linking to it.