Solved

Passing a filename as a variable to window.open

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

739 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