Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window.Open Nightmare...

Status
Not open for further replies.

CSUKNic

Technical User
Feb 3, 2002
62
GB
Hi,

I am trying to get a button to open a new window that will display a PDF File for customers to download. I can make the window open, and I can get it the right size. But within the cmomand

window.open(url,name,functions)

I cannot make the name part work, and always get the hyperlink address shown at the top of the screen, whereas I want to put a title there. If I actually put a name within the "" or '', I get syntax errors or illegal calls.

Attached below is the source for the page. If anyone can tell me what I'm doing wrong it would be appreciated. Also can anybody tell me how to determine what screen resolution somebody is using, as my site requires 1024x768 to work properly.


-- Code --

<html>

<head>
<meta name=&quot;generator&quot; content=&quot;GoLive CyberStudio 3&quot;>
<title>bottom navigation page - general</title>
<script language=&quot;JAVASCRIPT&quot; cyberversion=&quot;N1.2&quot;><!--
// This script copyright 1997, Tom Negrino and Dori Smith.
// This script is from &quot;JavaScript for the WWW, Visual QuickStart Guide, 2nd Ed.&quot;
// For more information, see < // This script may be used and modified, but the copyright notice must remain intact.

if (document.images) {
img1on = new Image
img1off = new Image
img2on = new Image
img2off = new Image

img1on.src = &quot;cmainmenu_hlt.gif&quot;
img1off.src = &quot;cmainmenu.gif&quot;
img2on.src = &quot;corp_fact_hlt.gif&quot;
img2off.src = &quot;corp_fact.gif&quot;
}
else {
img1on = &quot;&quot;
img1off = &quot;&quot;
img2on = &quot;&quot;
img2off = &quot;&quot;

}

// This script was adapted from one of Nick Heinle's scripts from
// his book &quot;Designing with Javascript&quot;


function changePages(bot_frameURL,top_frameURL,infoURL,picURL) {
parent.navigator_bot_frame.location.href = bot_frameURL;
parent.navigator_top_frame.location.href = top_frameURL;
parent.info_frame.location.href = infoURL;
parent.picture_frame.location.href = picURL;
}

function openNewWindow(url) {
window.open(url,&quot;&quot;,'width=800,height=600,menubar=yes');
}



window.onError=null;


var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_mac = (agt.indexOf(&quot;mac&quot;)!=-1);


// -->
</script>
</head>

<body background=&quot;cdivide.gif&quot;>
<TABLE VALIGN=&quot;TOP&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot; BORDER=&quot;0&quot; WIDTH=100% HEIGHT=&quot;100%&quot;>
<TR>
<TD VALIGN=&quot;TOP&quot; WIDTH=&quot;100&quot;>

<!--1st cell of outside table -->

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; WIDTH=&quot;100%&quot; height=&quot;100%&quot;>
<TR ALIGN=&quot;CENTER&quot; HEIGHT=&quot;100%&quot;>
<TD ALIGN=&quot;TOP&quot; ALIGN=&quot;CENTER&quot; width=&quot;338&quot; height=&quot;100%&quot; valign=&quot;top&quot;><img src=&quot;c_nav_bot_text.gif&quot; width=&quot;226&quot; height=&quot;25&quot; border=&quot;0&quot; name=&quot;home&quot;></a></td>
</TR>
</TABLE>
</TD>

<CENTER>
<!--nested table in 2nd cell -->
<td ALIGN=&quot;RIGHT&quot; width=&quot;100%&quot; valign=&quot;TOP&quot;>

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; height=&quot;100%&quot;>
<TR ALIGN=&quot;CENTER&quot; HEIGHT=&quot;100%&quot;>
<td align=&quot;center&quot; width=&quot;90&quot; height=&quot;100%&quot;><a href=&quot;javascript:eek:penNewWindow('factsheet.pdf')&quot; onmouseover=&quot;document.pdf.src=img2on.src, window.status='Home';return true&quot; onmouseout=&quot;document.pdf.src=img2off.src&quot;><img src=&quot;corp_fact.gif&quot; width=&quot;85&quot; height=&quot;25&quot; border=&quot;0&quot; alt=&quot;Printable Factsheet&quot; name=&quot;pdf&quot;></a></td>
<td align=&quot;center&quot; width=&quot;85&quot; height=&quot;100%&quot;><a href=&quot;javascript:changePages('nav_bot_gen.html','nav_top_empty.html','info_gen.html','pic_show_rookery.html')&quot; onmouseover=&quot;document.gohome.src=img1on.src, window.status='Home';return true&quot; onmouseout=&quot;document.gohome.src=img1off.src&quot;><img src=&quot;cmainmenu.gif&quot; width=&quot;85&quot; height=&quot;25&quot; border=&quot;0&quot; alt=&quot;Back to Welcome page&quot; name=&quot;gohome&quot;></a></td>
</TR>

</TABLE>
</CENTER>
</TD>

</TR>
</TABLE
</body>

</html>
 
If you were to modify your current openNewWindow function to match this:

Code:
function openNewWindow(url)
{
  var myWin = window.open(url,'','width=800,height=600,menubar=yes');
  if (arguments.length == 2) myWin.document.title = arguments[1];
}

And then using the following code in your HTML:

Code:
<a href=&quot;javascript:openNewWindow('test.pdf');&quot;>Test</a>
<a href=&quot;javascript:openNewWindow('test.pdf','With a title');&quot;>Test with a title</a>

You can choose to specify a title (or not). If the extra parameter is supplied then it will change the title of the document, if not, then it won't.

There are conflicting reports regarding the document.title property. It is supposed to be read only, but it can be set (if you are in the same domain as the document) on most of the older browsers (apparently).

Personally, the code example did *not* work on my IE 6 Windows when testing it from my hard disk (or from a web server). Specifically it gave an &quot;unspecified error&quot; when trying to set the title.

You may get better mileage on this example.

Jeff
 
CSUKNic,

the &quot;name&quot; part of the window.open() function is NOT the same as document.title.

the &quot;name&quot; is something you can use to target links and form submissions, such as:
Code:
<script>
window.open(&quot;foo.html&quot;, &quot;myPage&quot;, &quot;height=400,width=300&quot;);
</script>

<form target=&quot;myPage&quot;>
  <input type=&quot;submit&quot;/>
</form>

the name argument has nothing to do with what displays in the window's caption.

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top