?
Solved

Javascript Question

Posted on 2003-02-27
10
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

770 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