Link to home
Start Free TrialLog in
Avatar of kaz070397
kaz070397

asked on

Passing a filename as a variable to window.open

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!
ASKER CERTIFIED SOLUTION
Avatar of Trevor013097
Trevor013097

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaz070397
kaz070397

ASKER

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.
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.
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.