Solved

Passing a filename as a variable to window.open

Posted on 1997-07-03
4
473 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

740 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