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,fstrname,w,h,features)  {
  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,fstrname,settings);
  win.document.title = b;
  win.window.focus();
 
}

</script>
NewzoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xchenxchenCommented:
I'v done it already. I'v tried on my IE5.5 and it works well. See the following x.html and xx.html. x.html opens xx.html. Put them in the same directory and load x.html. As you see xx.html is loaded with your own title.

---- x.html ----
<html>
<head>
<script type="text/javascript" language="JavaScript">
var win = null;
function newWindow(fstrpage,fstrname,w,h,features)  {
 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,fstrname,settings);
 win.document.title = b;
 win.window.focus();
}
newWindow('xx.html','xx',300,300,'');
</script>
</head>
<body>
</body>
</html>

---- xx.html ----
<html><head>
<title>XXXXXX</title>
</head>
<body>
HI
</body>
</html>
0
xchenxchenCommented:
Correction on my previous comment. I really meant "YOU'v done it already" in the first sentence.
0
NewzoneAuthor Commented:
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.pdf','','750','550','resizable,scrollbars')">

What do you think?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

xchenxchenCommented:
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.
0
thirdCommented:
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,fstrname,pdfpage,w,h,features)  {
  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,fstrname,settings);
  win.document.title = b;
  win.document.getElementById('myframe').src = pdfpage;
  win.window.focus();
}
newWindow('test.html','xx','recommendation_form.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>

0
thirdCommented:
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,fstrname,pdfpage,w,h,features)  {
  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,fstrname,settings);
  win.document.write('<html><head><title>'+b+'</title></head><body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">');
  win.document.write('<iframe width="100%" height="100%" src="'+pdfpage+'"></iframe>');
  win.document.write('</body></html>');
  win.document.close();
  win.focus();
//  win.document.title = b;
//  win.document.getElementById('myframe').src = pdfpage;
//  win.document.myframe.src = pdfpage;
//  win.window.focus();
}
newWindow('test.html','xx','recommendation_form.pdf',300,300,'');
</script>
</head>
<body>
</body>
</html>

those in comments are from the old code above. you can delete those later.
0
thirdCommented:
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,features)  {
  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',settings);
  win.document.write('<html><head><title>'+b+'</title></head><body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">');
  win.document.write('<iframe 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.href,300,300,'');return false">yourpdf</a>
</body>
</html>
0
NewzoneAuthor Commented:
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!
0
thirdCommented:
"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.)"

if you want it to open at the top left change

var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;

to

var winl = 0;
var wint = 0;

or just

var settings = 'height=' + h + ',';
 settings += 'width=' + w + ',';
 settings += 'top=0,';
 settings += 'left=0,';
 settings += features;

if you don't want to use variables.


"what is iframe"

IFRAME stand for Inline Frame which works to include other objects including other html documents. it is very similar to frames only that you use it within the document body.

for more info,

http://www.htmlhelp.com/reference/html40/special/iframe.html


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NewzoneAuthor Commented:
Thanks a million!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.