Solved

Passing a filename as a variable to window.open

Posted on 1997-07-03
4
450 Views
Last Modified: 2012-06-22
I am trying to set up a web page whereby you can click on a word and a little window pops up telling you the definition of that word.  Each defn is a unique little text file.
I want to pass the name of the defn from the link eg
<a href-javascript:defnwin(bananad)> Defn of banana</a>
and pass it into the function:
function defnwin(filename)
and for it to window.open"../defns/filename" etc etc

I have managed to get it working just by declaring eaach little defn as a variable up at the top but this is not practical to do it through all my web pages (lots of defns)

So perhaps you can help and tell me how to do it or a better way to do it.

Thanks!
0
Comment
Question by:kaz070397
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Trevor013097 earned 100 total points
ID: 1268021
Okay,

In your function have something like:-

function defnwin(defObject) {
   window.open " + defObject + ";
   }


then in your link use something like

<A HREF="javascript:defwin(bananad.htm)">Banana Definition</A>

Hope this helps


0
 

Author Comment

by:kaz070397
ID: 1268022
Hi

Need some more clarification.  Still not quite working.
1) in the window.open line.  Should it be exactly as you typed it and that is it for that line or the full normal line with ("+defnOb+", "defn_win" menubar=0 etc etc
2) How can I work it so that all the defns files are stored in a directory called ../defns/appledef.html?
3) i got the error message string.html is not a number ??????

Don't worry this confusion is my fault not yours!! I am a Javascript virgin as it were.

Thanks for your help

Karen.
0
 
LVL 5

Expert Comment

by:Trevor013097
ID: 1268023
Hi Karen,

I have refined the script somewhat and now it works perfectly and also includes the directory reference aswell.

<HTML>
<TITLE>Definition Pop-Up Script</TITLE>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--

function defnWin(defObject) {
      winFeatures = "menubar=0, scrollbars=0, width=130, height=415";
      var urlVar = ""
      urlVar = ("../files/" + defObject);
      definition = window.open(urlVar, "PopWindow", winFeatures);
      }

/-->
</SCRIPT>

</HEAD>

<BODY BGCOLOR="#FFFFFF">

<A HREF="Javascript:defnWin('banana_def.htm')">Banana</A><BR>
<A HREF="Javascript:defnWin('apple_def.htm')">Apple</A><BR>
<A HREF="Javascript:defnWin('orange_def.htm')">Orange</A>

</BODY>

</HTML>

Hope it is what you were after.  It has given me a great idea for our site, a nice floating toolbar.
0
 

Author Comment

by:kaz070397
ID: 1268024
Thanks!! At long last I can plod on and get this done.

If you looking for a floating toolbar, have you visited Ferrari's site?  They have one - very nifty.  It is also the site I used to get my Javascript thinking cap on and start teaching myself it.

Check out http://www.shell-ferrari.com  (select non jave version)

Good luck!!!

Karen.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now