Re: Positioning content with div tags - whats wrong here?



On Dec 4, 11:01 am, Randell_D <fiprojects....@xxxxxxxxx> wrote:
I got some javascript within Dreamweaver MX and am trying to

Oops. That's a bad place to get JavaScript.

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

That's a good idea.

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">

Get rid of that language attribute. Optionally, add type="text/
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 )

I assume you mean y<0, but the whole thing is silly. Why set x and y
to -1 in the first place?

{ y = Math.floor(screen.height/5); }
// Reference the tag using a method valid for this browser

You can't reference a tag. Dreamweaver meant to say element.

var pointer=new Object();

There is no need to instantiate an Object here. Also, "pointer" is a
lousy name for a variable in any language (and particularly
inappropriate in JavaScript.)

if( document.all[tag] )

What if the "all" property does not exist? Change to:

if (document.all)

{ pointer=document.all[tag]; }

if( document.getElementById(tag) )

Same here and put an else before the if.

{ pointer=document.getElementById(tag); }
// Position the pointer

Check that "pointer" was set to an element with a style property
before proceeding any further.

if (pointer && pointer.style) {

pointer.left=x;

pointer.style.left = x + 'px';

pointer.top=y;

Same.

// Display our content
if( pointer.visibility )
{
pointer.visibility = "hidden";
pointer.document.write(content);
pointer.document.close();
pointer.visibility = "visible";
}

Delete that clause as you can't find an element in NN4 with
document.all or document.getElementById.

else
{
pointer.display = "none";

Delete.

pointer.innerHTML = content;
pointer.display = "block";

pointer.style.position = 'absolute';

The computed style will be now be 'block' and the element will be
positioned where you want it, assuming it doesn't have a positioned
parent.

}
return true;

Why return anything unconditionally?

}


}

positionThis( "our crap", "ourID", 400, 400 );
</script>

.



Relevant Pages

  • Re: Adding rows to a table, works in Firefox, but not IE
    ... mark-up and they will be implied, the opening tag by any TR ... It sounds like the sort of thing that might come form someone familiarwith Java who has not understood that javascript is not Java. ... What is an inner function declaration? ... your assignment to it is an assignment to a property of the ...
    (comp.lang.javascript)
  • Re: RFD: How To Recognize Bad Javascript Code
    ... Elements consist of tags ... Your example `script' elements are empty where they should have ... | Using the pseudo-protocol javascript in the href is never valid. ... Some web developers use this to work ...
    (comp.lang.javascript)
  • Re: check email address is real
    ... MVP FrontPage ... it doesn't understand the tag it ignores it and reads whatever's inside. ... I just wouldn't put money on the noscript tag distinguishing between users ... The idea is, spambots do NOT execute javascript, and therefore ...
    (microsoft.public.frontpage.programming)
  • Re: Completely OT
    ... the tag. ... also don't forget to sanitize the data you receive before committing ... it to the database, or someone can hack the javascript and send an SQL ...
    (comp.lang.python)
  • Re: Search for values in between two values in a string?
    ... If the application is on the client side, then you can just pure JavaScript or JSCRIPT or VBSCRIPT to access the Document.* methods and properties and events. ... but that finds a tag id=value, ... DOM has GetElementByTag and GetElementByName, ... In fact, jQuery is so small, fast and sweet, Microsoft has announced full jQuery support in ASP.NET. ...
    (microsoft.public.dotnet.languages.vb)