Flytta runt ett object med musen??
Hej!Jag försöker flytta runt en <h1> i ett fönster som jag har öppnat från ett annat.
Men jag får liksom inte tag i själva <h1>-objektet.
Kan någon komma på hur man ska göra så vore det toppen!!!
Jag vill gärna ha all kod i 3 olika filer istället för js-inline. För jag vill kunna spara undan information om hur användaren placerar <h1> objektet och sedan skicka iväg allt till en Servlet från HTML-fil 1.
Därför har jag mina filer så här (Tror att denna struktur borde funka, men jag kan mycket väl ha fel.):
HTML-fil 1
<html>
<head>
</head>
<body>
<input type=\"button\" name=\"b4\" value=\"open\">
</body>
</html>
Js-fil:
var newWindow =\"\";
var Event = null;
var objectX =0;
var objectY =0;
currentObj = null;
function openNewWindow()
{
newWindow = window.open(\"http://fredrik/develop/IP3/lektion8/test8b.html\",\'opensmall\',\'width=770,height=445,toolbar=no\');
if (newWindow.opener == null)
{
newWind.opener = self;
}
}
//-------------------TITEL--------------------------------------------------------
var picked = 0;
function pickTitle(e, obj)
{
picked = 1;
alert(\"pickTitle\");
e = newWindow.event;
currentObj = obj;
newWindow.document.all.title.style.pixelLeft = e.clientX;
newWindow.document.all.title.style.pixelTop = e.clientY;
}
function moveTitle()
{
alert(\"moveTitle\");
if(picked == 1)
{
if(currentObj != null)
{
objectX = newWindow.event.clientX;
objectY = newWindow.event.clientY;
newWindow.document.all.title.style.pixelLeft = window.event.clientX;
newWindow.document.all.title.style.pixelTop = window.event.clientY;
}
}
}
function placeTitle()
{
alert(\"placeTitle\");
newWindow.document.all.title.style.pixelLeft = objectX;
newWindow.document.all.title.style.pixelTop = objectY;
currentObj = null;
}
//window.onload = openNewWindow;
window.document.all.b4.onclick = openNewWindow;
newWindow.onload = \"newWindow.document.all.title.ondragenter = new Function(\'opener.pickTitle(event, newWindow.document.all.title)\');\"
newWindow.onload = \"newWindow.document.all.title.onmouseover = opener.placeTitle;\"
newWindow.onload = \"newWindow.document.all.title.onmouseover = opener.moveTitle;\"
HTML-fil 2
<html>
<head>
<link href=\"css/test8.css\" rel=\"stylesheet\" type=\"text/css\"/>
</head>
<!--<body id=\"body\" onload=\"document.all.title.onmouseover=opener.pickObject;\">-->
<body id=\"body\">
<form name=\"form\">
<h1 id=\"title\" class=\"im\">Fönster 2</h1>
<div id=\"d\"></div>
<input type=\"button\" name=\"move\" value=\"move\">
<script type=\"text/JScript.Encode\" src=\"js/testII.js\"></script>
<!--<script language=\"Javascript\" src=\"js/test.js\"></script>-->
</form>
</body>
</html>
Men jag kan liksom inte greppa/plocka upp <h1>-objektet i HTML-fil 2
Med hoppfulla hälsningar
Fredrik
