Newzone
asked on
Javascript Question
I have a new document window opening up from a link. I want the title bar to be a generic statement. I have the code below, but it's not working. Can anyone tell me why?
Thanks in advance!
Michelle
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam e,w,h,feat ures) {
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn ame,settin gs);
win.document.title = b;
win.window.focus();
}
</script>
Thanks in advance!
Michelle
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn
win.document.title = b;
win.window.focus();
}
</script>
Correction on my previous comment. I really meant "YOU'v done it already" in the first sentence.
ASKER
Hi xchenxchen,
I tried what you gave me and it opens a third window. I think I didn't explain my project very well. I have this window open from a link and it brings in a pdf file (which may be why I can't change the title bar.) The text above is what I have on the page where all the links are and I've added below how I call the document and new window.
<a href="#null" onClick="newWindow('ace.pd f','','750 ','550','r esizable,s crollbars' )">
What do you think?
I tried what you gave me and it opens a third window. I think I didn't explain my project very well. I have this window open from a link and it brings in a pdf file (which may be why I can't change the title bar.) The text above is what I have on the page where all the links are and I've added below how I call the document and new window.
<a href="#null" onClick="newWindow('ace.pd
What do you think?
I get it now. In this case you may not be able to do it as the control is taken over by the Adobe plug-in. You may seek for better answer.
Hi Michelle,
here's a workaround. i've set the script to open another page (test.html in my example) which contains an iframe that occupies the whole page. then i modified newWindow function and sets the source of the iframe to the pdfpage parameter. here is the new script,
opener.html
------------
<html>
<head>
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam e,pdfpage, w,h,featur es) {
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn ame,settin gs);
win.document.title = b;
win.document.getElementByI d('myframe ').src = pdfpage;
win.window.focus();
}
newWindow('test.html','xx' ,'recommen dation_for m.pdf',300 ,300,'');
</script>
</head>
<body>
</body>
</html>
test.html
------------
<html>
<head>
<title>your title</title>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<iframe id="myframe" width="100%" height="100%" src="about:blank"></iframe >
</body>
</html>
here's a workaround. i've set the script to open another page (test.html in my example) which contains an iframe that occupies the whole page. then i modified newWindow function and sets the source of the iframe to the pdfpage parameter. here is the new script,
opener.html
------------
<html>
<head>
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn
win.document.title = b;
win.document.getElementByI
win.window.focus();
}
newWindow('test.html','xx'
</script>
</head>
<body>
</body>
</html>
test.html
------------
<html>
<head>
<title>your title</title>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<iframe id="myframe" width="100%" height="100%" src="about:blank"></iframe
</body>
</html>
this is better it uses only your main page. the child window is written on the fly
<html>
<head>
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam e,pdfpage, w,h,featur es) {
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn ame,settin gs);
win.document.write('<html> <head><tit le>'+b+'</ title></he ad><body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">');
win.document.write('<ifram e width="100%" height="100%" src="'+pdfpage+'"></iframe >');
win.document.write('</body ></html>') ;
win.document.close();
win.focus();
// win.document.title = b;
// win.document.getElementByI d('myframe ').src = pdfpage;
// win.document.myframe.src = pdfpage;
// win.window.focus();
}
newWindow('test.html','xx' ,'recommen dation_for m.pdf',300 ,300,'');
</script>
</head>
<body>
</body>
</html>
those in comments are from the old code above. you can delete those later.
<html>
<head>
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn
win.document.write('<html>
win.document.write('<ifram
win.document.write('</body
win.document.close();
win.focus();
// win.document.title = b;
// win.document.getElementByI
// win.document.myframe.src = pdfpage;
// win.window.focus();
}
newWindow('test.html','xx'
</script>
</head>
<body>
</body>
</html>
those in comments are from the old code above. you can delete those later.
hmmm, i haven't removed unnecessary codes. here is the final script,
<html>
<head>
<script type="text/javascript" language="JavaScript">
function newWindow(pdfpage,w,h,feat ures) {
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open('','win',setti ngs);
win.document.write('<html> <head><tit le>'+b+'</ title></he ad><body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">');
win.document.write('<ifram e width="100%" height="100%" src="'+pdfpage+'"></iframe >');
win.document.write('</body ></html>') ;
win.document.close();
win.focus();
}
//newWindow('yourpdf.pdf', 300,300,'' );
</script>
</head>
<body>
<a href="yourpdf.pdf" onclick="newWindow(this.hr ef,300,300 ,'');retur n false">yourpdf</a>
</body>
</html>
<html>
<head>
<script type="text/javascript" language="JavaScript">
function newWindow(pdfpage,w,h,feat
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open('','win',setti
win.document.write('<html>
win.document.write('<ifram
win.document.write('</body
win.document.close();
win.focus();
}
//newWindow('yourpdf.pdf',
</script>
</head>
<body>
<a href="yourpdf.pdf" onclick="newWindow(this.hr
</body>
</html>
ASKER
Wow, that just about did it. Two things, how do I get it to open back in the left edge (it opens a full window that starts on about the middle of the screen.) I didn't notice that you changed anything in the setting code so I don't know why it's doing that now. And what is "iframe" I haven't seen that before. I had the idea I needed something like that, but I didn't really know how to look for it. Thanks a lot!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a million!
---- x.html ----
<html>
<head>
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrnam
var b = "You are in the FSTR Website.";
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(fstrpage,fstrn
win.document.title = b;
win.window.focus();
}
newWindow('xx.html','xx',3
</script>
</head>
<body>
</body>
</html>
---- xx.html ----
<html><head>
<title>XXXXXX</title>
</head>
<body>
HI
</body>
</html>