script error

  • Vladdrac
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2136
  • Loc: Louisville, Ky

Post 3+ Months Ago

I have made a flash movie that I am trying to get into a popup window. I know nothing about javascript but I have been using this code in the head of my html

Code: [ Select ]
<head>
<script language="JavaScript" type="text/javascript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 192,top = 144');");
}
</script>

<title>Untitled-2</title>
</head>
  1. <head>
  2. <script language="JavaScript" type="text/javascript">
  3. function popUp(URL) {
  4. day = new Date();
  5. id = day.getTime();
  6. eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 192,top = 144');");
  7. }
  8. </script>
  9. <title>Untitled-2</title>
  10. </head>


and I have it linked on another page like this

Code: [ Select ]
<A HREF="javascript:popUp('http://www.vladdracworld.com/web_images/space.html')">Popup</A>


I get a script error in my browser. What is wrong?

Also, if I make a popup will it be possible for gecko browsers too see the popup? or will it just play in a new window?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

What error are you getting? The code worked for me in IE and Firefox. You should probably be declaring your variable with the var keyword, although failing to do so has never really caused me any problems. I also avoid using id as a variable name because it caused me a problem once but it doesn't seem to be doing so here when I try to run the code. It pops up the flash movie as it should.

You say you have the link on another page. Does that mean the function code is embedded in the head of one page and the function call appears on another page? You won't be able to do that because the code for the function won't be available on a different page unless you put the code into an external .js file (just the plain function code with no script tags) and then link to it via the script tag in the head of any pages that call the code it contains:

Code: [ Select ]
<script language="JavaScript" type="text/javascript" src="pop.js"> </script>


and then stick the function code inside a file called pop.js or whatever and you can call the function from a link on any page that includes the script tag above.
  • Vladdrac
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2136
  • Loc: Louisville, Ky

Post 3+ Months Ago

I don't get it, when I hover over the link i get
Code: [ Select ]
popUp('http://www.vladdracworld.com/web_images/space.html')">


Shouldn't that open the link in my popup. It really is bugging the crap out of me, and I have no idea why it is working for you and not me.

I got rid of id and used var instead of eval as you suggested, still nothing. The link won't even open up, just like before.

you where right, before I put the function code in the head of the actual html that has the flash embeded in it, and the call is in the body of another.

I know I can make the pop.js file, which makes it easier to work with.....thanks. But I am not 100% what exactly you mean here
Quote:
put the code into an external .js file (just the plain function code with no script tags) and then link to it via the script tag in the head of any pages that call the code it contains:

Code:
<script language="JavaScript" type="text/javascript" src="pop.js"> </script>


and then stick the function code inside a file called pop.js or whatever and you can call the function from a link on any page that includes the script tag above.


Are you saying to put that include in the head of the flash.html and the doc that has the link to it?

Sorry If I did not understand you correctly
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I didn't mean subsitute var for eval but to declare the variable themselves with var like this:

Code: [ Select ]
var theId = day.getTime();


Here's the pop.js file I used to test it:

Code: [ Select ]
function popUp(URL) {
var day = new Date();
var theID = day.getTime();
eval("page" + theID + " = window.open(URL, '" + theID + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 192,top = 144');");
}
  1. function popUp(URL) {
  2. var day = new Date();
  3. var theID = day.getTime();
  4. eval("page" + theID + " = window.open(URL, '" + theID + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 192,top = 144');");
  5. }


and the html file:

Code: [ Select ]
<html>
<head>
<script language="JavaScript" type="text/javascript" src="pop.js"> </script>

<title>Untitled-2</title>
</head>
<body>
<A HREF="javascript:popUp('http://www.vladdracworld.com/web_images/space.html')">Popup</A>
</body>
</html>
  1. <html>
  2. <head>
  3. <script language="JavaScript" type="text/javascript" src="pop.js"> </script>
  4. <title>Untitled-2</title>
  5. </head>
  6. <body>
  7. <A HREF="javascript:popUp('http://www.vladdracworld.com/web_images/space.html')">Popup</A>
  8. </body>
  9. </html>


When I click that link it opens the popup and starts loading the flash which is the behavior I assume you are looking for. Since you have put the function call in the href attribute it is normal for it to show in the status bar when you hover over it. You would include the script file in any html page that uses the popUp function, so you don't need to include it in the page that holds the flash movie itself since it has no link to the popup code.
  • Vladdrac
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2136
  • Loc: Louisville, Ky

Post 3+ Months Ago

ok, damn, I feel stupid now. I had the script in the head of the doc that had the flash in it. When all I needed to do is put the script and the link in the page that had the link.

Hey thanks alot for your help! works now..cool

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 79 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.