R
Randell_D
I got some javascript within Dreamweaver MX and am trying to
understand it - I got it to work and even managed to make some changes
to make it fit my web app but I don't like to use something unless I
am comfortable supporting it. So I've begun to write my own and am
failing to get it to work...
In the code below, I would have expected the words "our crap" to be
located 400px down, 400px from the left but instead the words just
appear in top left corner regardless of the co-ordinates i use.
This is my version - I'd appreciate it if someone could direct me as
to what is missing...
After the <BODY> tag I have the following
<div id="ourID"></div>
<script language="javascript">
function positionThis( content , tag, x, y )
{ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup the environment
// If we were not passed co-ordinates so prepare to create dynamic
values
if( arguments.length < 3 )
{ x=-1;
y=-1;
}
// We don't have a valid x co-ordinate so create one
if( x<0 )
{ x = Math.floor(screen.width/3); }
// We don't have a valid y co-ordinate so create one
if( x<0 )
{ y = Math.floor(screen.height/5); }
// Reference the tag using a method valid for this browser
var pointer=new Object();
if( document.all[tag] )
{ pointer=document.all[tag]; }
if( document.getElementById(tag) )
{ pointer=document.getElementById(tag); }
// Position the pointer
pointer.left=x;
pointer.top=y;
// Display our content
if( pointer.visibility )
{
pointer.visibility = "hidden";
pointer.document.write(content);
pointer.document.close();
pointer.visibility = "visible";
}
else
{
pointer.display = "none";
pointer.innerHTML = content;
pointer.display = "block";
}
return true;
}
positionThis( "our crap", "ourID", 400, 400 );
</script>
understand it - I got it to work and even managed to make some changes
to make it fit my web app but I don't like to use something unless I
am comfortable supporting it. So I've begun to write my own and am
failing to get it to work...
In the code below, I would have expected the words "our crap" to be
located 400px down, 400px from the left but instead the words just
appear in top left corner regardless of the co-ordinates i use.
This is my version - I'd appreciate it if someone could direct me as
to what is missing...
After the <BODY> tag I have the following
<div id="ourID"></div>
<script language="javascript">
function positionThis( content , tag, x, y )
{ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup the environment
// If we were not passed co-ordinates so prepare to create dynamic
values
if( arguments.length < 3 )
{ x=-1;
y=-1;
}
// We don't have a valid x co-ordinate so create one
if( x<0 )
{ x = Math.floor(screen.width/3); }
// We don't have a valid y co-ordinate so create one
if( x<0 )
{ y = Math.floor(screen.height/5); }
// Reference the tag using a method valid for this browser
var pointer=new Object();
if( document.all[tag] )
{ pointer=document.all[tag]; }
if( document.getElementById(tag) )
{ pointer=document.getElementById(tag); }
// Position the pointer
pointer.left=x;
pointer.top=y;
// Display our content
if( pointer.visibility )
{
pointer.visibility = "hidden";
pointer.document.write(content);
pointer.document.close();
pointer.visibility = "visible";
}
else
{
pointer.display = "none";
pointer.innerHTML = content;
pointer.display = "block";
}
return true;
}
positionThis( "our crap", "ourID", 400, 400 );
</script>