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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new window from external .js file

Status
Not open for further replies.

jockm

Technical User
Aug 13, 2002
41
GB
I am wanting to open a new window and control the size and placement of that new window from an external .js file.

So far I cannot do it, because the external file doesnt allow a javascript command imbedded in it.

I am sure there is a way to do this, and would love to know how.

THANKS!

jockm
 
I don't understand what's your problem is, this is as easy as without external js-files.

Place this in text file and save as scripts.js:

fucntion openNew(url, w, h) {
winprops = "resizable=yes,status=no,toolbar=no,width=" + w + ",height=" + h + ",top=200,left=400";
a = window.open(url,"popup",winprops);
}

Don't add anything to it (like <script> tags - this is an error).
Then, in your html page do this:

<head>
. . .
<script language=&quot;javascript&quot; src=&quot;scripts.js&quot;></script>
</head>
<body>
<a href=&quot;javascript:eek:penNew('somepage.html', 300, 200)&quot;>open new window</a>
. . .
</body></html>

This will open a new window with specified width/height. Modify these parameters in function call in <a> tag to change it to fit your needs.

That's all.
 
Hi, thanks for your reply.

I realised that I didnt make my problem clear. I have created an external file, navbar.js, which is intended to replace my current frames navbar.

This navbar.js file has many document.write statements in it, and the links on the navbar are anchored to various different local html files.

In some cases I want to open one of these html files in a new window, which I can size and position on the screen. If I try to put a javascript command within the document.write, it simply wont work.

I can use ordinary html, with TARGET, but then I cannot size the new window that opens with my html file in it.

So I am looking for a way to embed within my document.write command the code for opening a new window that I can add the height and width parameters.

All this must stay within the navbar.js file.

Hope its clearer now.

thanks

jock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top