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

opening popup window from external .js file 1

Status
Not open for further replies.

jockm

Technical User
Aug 13, 2002
41
0
0
GB
I have created an external .js file (navbar.js) to replace a framed navbar. This .js file is called out of my index.htm file

<script language=javascript&quot; src=navbar.js&quot;></script>

My navbar.js file looks like this

<!-- hide script
document.write(&quot;<A HREF='vision.thml'>Vision Statement</A><BR>&quot;)
document.write(&quot;<A HREF='costs.thml'>Costs Summary</A><BR>&quot;)
// end hiding script -->

The above fragment writes onto the index.htm page two lines with their anchors. Clicking Vision Statement opens a window with the vision.html file replacing index.htm. That works fine.

However, I would like when the Costs Summary link is clicked to open a new small window, 200 x 300 px wide.

So far I havent figured out how to do this, as I cannot imbed the width and height parameters into the document.write statement.

I feel sure there must be a way to accomplish what i want to do, and would appreciate some help/suggestions.

thanks

jock
 
hi jock,

no problem:
[tt]
document.write('<A HREF=&quot;#&quot; onclick=&quot;window.open(\'costs.html\',\'costsWin\',\'height=200,width=300\');return false;&quot;>Costs Summary</A><BR>')
[/tt]
a tip too: when writing html code with write(), I like to wrap the whole argument string in single quotes, as that lets you use double quotes in the html as normal.
=========================================================
if (!succeed) try();
-jeff
 
Okay Jeff, many thanks, I will go and try it.

I would also like to know a nice comprehensive, but readable book, where I can find out how to know lots of things about JavaScript, that I dont find in my JavaScript for dummys and Visual Quickstart books. For instance, I didnt see in my books the use of escape char as you used it in the example above.

cheers

jock
 
I have not found a bad O'reilly book and their JavaScript book in particular is pretty comprehensive. Even better, after you start to know what you're doing (or, as in my case, just think you do), it makes a great reference.
 
O'Reilly's &quot;Javascript: The Definitive Guide&quot; is a good one...

I must disagree with bvallet's comment &quot;I have not found a bad O'reilly book...&quot; though: ASP in a Nutshell is helpful but still lacks a lot of detail.

=========================================================
if (!succeed) try();
-jeff
 
Hi,
I have found

&quot;JavaScript Bible - Gold Edition&quot; by
Danny Goldman ( with a CD-ROM full of stuff)
to be my PC-side companion when working with JavaScript.

[profile]
 
Hiya

I tried the script you suggested

document.write('<A HREF=&quot;#&quot; onclick=&quot;window.open(\'costs.html\',\'costsWin\',\'height=200,width=300\');return false;&quot;>Costs Summary</A><BR>')

which is supposed to open a new small window with those parameters.

Regrettably, it does not work with Explorer 5.1 for Mac, and Netscape 4.7 for Mac, nor with iCab. Rather, it tries to open up the HREF file &quot;#&quot;.

I wonder if the script you suggested is too new for those browsers? If so, could you suggest a different way to do it?

I will keep at it, because once I can get this to work, I have solved my big problem of how to eliminate the frames from my site and still not have to update dozens of pages everytime I make a change to the information on the navbar.

And thanks for the tips on the books. Soon as possible I will acquire the 2 mentioned. I would also steer anyone away from JavaScript for Dummies. It seems to me to assume you already know everything about object programming.

jockm
 
jockm,

this may work for you:

document.write('<A HREF=&quot;javascript:window.open(\'costs.html\',\'costsWin\',\'height=200,width=300\');return false;&quot;>Costs Summary</A><BR>')
=========================================================
if (!succeed) try();
-jeff
 
Hi Jeff

Just after my last post, I discovered that I had omitted a closing paren, and lo and behold, your code worked perfectly.

THANK U !!!!

This cleared a huge block I had for 2 weeks, and I was able to make significant progress on my navbar.js over the weekend.

I have now got another small problem, which I will post on a new thread, but in case you are reading this, you might easily have the answer I expect:

now I wish to write on the fly from that navbar one of several images that the different main pages have. I am sure there is a way to do this using onLoad and passing my image to a function in that navbar.js file, and having a document.write() write it to the navbar that the navbar.js file is creating.

But so far I havent figured out the right code and how to pass my source image(s).

Thanks again!

jockm
 
I have already implemented a javascript navbar component (among many, many others). You can see it at in the horizontal orientation. (you'll find my navigable calendar component there too!)

Basically, you create an array -- just
Code:
.split()
a
Code:
String
-- and tack on my
Code:
.menu()
function.

Code:
javascript:&quot;About,Products,Services,Pricing,Contact&quot;.split(&quot;,&quot;).menu().write();

This was achieved by extending the
Code:
Array.prototype
to implement
Code:
.menu()
which returns a
Code:
String
. I've also extended the
Code:
String.prototype
to support its own
Code:
.write()
function... very handy! ::)

Or for even more fun ...

Code:
javascript:new Date().calendar().write();
[thumbsup2]

You may go to to view my latest improvements to the calendar component. If you decide to use my dynamicHTML3.js library (just File|Save As from the angelfire page), please credit me somewhere.

richard.renfrow@juno.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top