Solved

Passing a filename as a variable to window.open

Posted on 1997-07-03
4
442 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now