Click to See Complete Forum and Search --> : Open new window with onMouseOver()?


Fredde
01-30-2003, 07:37 AM
Pretty new javascripter here who really needs help.
What I´m trying to do is have a table with different building pictures on. (Not real buildings, painted. I´m working on a "build a little city script") What I want is that when you move your mouse over the different pictures a small window popups next to the picture with information on the building in the picture. The coding goes here: (dont mind the strange language in the coding, it is just some good ol´swedish)

Here is the function for the popup window:

function popupwin1() {
winpopup= window.open(",'popup','height=200,width=100,menubar=no,scrollbar=no,status=no,
toolbar=no,left=300,top=150');

winpopup.document.write('<HTML>\n<HEAD>\n');
winpopup.document.write('<TITLE>Byggnads information</TITLE>\n');
winpopup.document.write('</HEAD>\n');
winpopup.document.write('<BODY>\n');
winpopup.document.bgcolor= "#F0ECC9";
winpopup.document.fgcolor= "#75746D";
winpopup.document.write('<IMG SRC="images/murhogeroverhorn.gif" HEIGHT =20 WIDTH =20><BR>
winpopup.document.write('<PRE>Muren hjälper till att skydda ditt land och dina
grödor mot anfall</PRE>')

winpopup.document.close();
}


Here is when the window should popup:

output += '<TD BGCOLOR =#C7C4C4><input type ="image" SRC="images/huvudhus.gif" onMouseOver ="popupwin1();"></TD>';

output += '</TABLE>';
document.write(output);


Maybe you can´t open a new window with onMouseOver(), just with onClick()? I have no idea, so all help is greatly accepted

Dan Drillich
01-30-2003, 08:16 AM
Fredde,

You have several syntax errors. Try this -


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
</head>
<body>
<script type="text/javascript">
<!--

function popupwin1() {
winpopup= window.open("" ,'popup','height=200,width=100,menubar=no,scrollbar=no,status=no,

toolbar=no,left=300,top=150');

winpopup.document.write('<HTML>\n<HEAD>\n');
winpopup.document.write('<TITLE>Byggnads information</TITLE>\n');
winpopup.document.write('</HEAD>\n');
winpopup.document.write('<BODY>\n');
winpopup.document.bgcolor= "#F0ECC9";
winpopup.document.fgcolor= "#75746D";
winpopup.document.write('<IMG SRC="images/murhogeroverhorn.gif" HEIGHT =20 WIDTH =20><BR>') ;
winpopup.document.write('<PRE>Muren hjälper till att skydda ditt land och dina grödor mot

anfall</PRE>') ;

winpopup.document.close();
}

// -->
</script>


<input type ="image" SRC="images/huvudhus.gif" onMouseOver ="popupwin1();">



</body>
</html>

Cheers,
Dan

Fredde
01-30-2003, 10:19 AM
Thanks for your answers. I´ve tried out doing both of the solutions (copying Dans entire script) but none of them worked. I did find some small errors in my code but I corrected them and still not working. When I run the script in IE I can check whats wrong with it by clicking the litte button in the lower left corner. There it says error: An object was expected
And the line points to the </script> line

Have no idea what this means...

Dan Drillich
01-30-2003, 10:38 AM
It works for me on IE5.
The only things that have to be fixed on my script are several line breaks on the window.open and the last document.write commands. These extra line breaks should be removed.

Fredde
01-31-2003, 07:33 AM
Well, first of all thank you for your patience with a "pretend to know what he is doing" scripter.

First Dan, If you copy the script you have written in the reply into a new html document and run it, it works? A new window pop ups when you move the mouse over the picture? Well, thios do not work for me. I´ve tried copying the exact script you´ve written (with and without altering line breaks) and it doesnt work, no new window is created.

I dont know, I´m using IE 6 but it should still work with IE6, right?

Dave, this part, is it only put in the body part, not in the Function? Because there is no onMouseover in the function but maybe you still should write return true; on its last line?

""onMouseOver ="popupwin1();return true;"

All events should have either a true or a false value returned to them. ""

Dan Drillich
01-31-2003, 09:32 AM
Fredde,

Please try the script at -

http://www.geocities.com/ddrillich

Cheers,
Dan

Fredde
01-31-2003, 09:57 AM
Thank you, and thank you again...
The script you have written Dan, works great. Moving the mouse over the picture creates a new, wonderful window.

Please, Oh please, tell me the magic....

On a more serious note, what did I do wrong? How are your script coded?

Dan Drillich
01-31-2003, 10:10 AM
Just view source.

Fredde
01-31-2003, 10:54 AM
.....I´m stupid.......Actually I know you can view source but somehow missed that now......I promise.......

Anyway thanks a lot for all your help! I´ll guess it wont be long before I need help again but I´ll try to work out all my own problems as much as I can before I start posting noobie questions here again...

Dan Drillich
01-31-2003, 10:59 AM
We are all learning – actually it’s all about learning how to learn.