Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Javascript Question

Posted on 2003-02-27
10
Medium Priority
?
227 Views
Last Modified: 2013-12-16
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>
0
Comment
Question by:Newzone
  • 4
  • 3
  • 3
10 Comments
 

Expert Comment

by:xchenxchen
ID: 8037437
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
 

Expert Comment

by:xchenxchen
ID: 8037450
Correction on my previous comment. I really meant "YOU'v done it already" in the first sentence.
0
 

Author Comment

by:Newzone
ID: 8037868
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:xchenxchen
ID: 8037988
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
 
LVL 30

Expert Comment

by:third
ID: 8038158
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
 
LVL 30

Expert Comment

by:third
ID: 8038224
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
 
LVL 30

Expert Comment

by:third
ID: 8038300
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
 

Author Comment

by:Newzone
ID: 8038736
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
 
LVL 30

Accepted Solution

by:
third earned 400 total points
ID: 8038824
"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
 

Author Comment

by:Newzone
ID: 8042791
Thanks a million!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question