Position Floating Div respect to top&left of window document

I am trying to make a cross-browser floating div that "floats" on top of the window, with absolute position of  left-150px top-200px.  I got it working in Firefox with the following code:

var rng=document.createRange();  
rng.selectNode(document.body);  
document.body.appendChild(rng.createContextualFragment(myDiv));

where myDiv is set to have absolute position style that i need:

style="position:absolute;top:200px;left:150px;"

I can't get this to work on IE.  Anyone know the IE version of the code that I have above for Firefox?  Basically, appending it to the body and setting the position to some absolute position(may have to set the z-index as well).  Any suggestions/help will be greatly appreciated.

Thank you.  
mxyztplk333Asked:
Who is Participating?
 
LakioConnect With a Mentor Commented:
IE need to have it like this:

function addSuperDiv( linkElm )
{
	var element = createDomElement( 'div', document.body, 'The text in the div asdf asdfasdf asdf asdfa sdf ',  'id', 'superDiv' );
	element.style.position = 'absolute';
	element.style.left = '40px';
	element.style.top = '80px';
	element.style.background = '#F0C';
	
	linkElm.parentNode.removeChild( linkElm ); // deletes the link
}

Open in new window

0
 
LakioCommented:
Send a screenshot of it in Firefox.
0
 
scrathcyboyCommented:
absolute positioning tends to give cross browser problems, each browser interprets the starting point for the absolute somewhat differently, depending on the elements in the table.  Try both IE6 and 7, see what difference there is.  If the problem is just in IE6 (which it usually is) I wouldn't worry too much about it.  Also test on the MAC browsers for full X-browser compat.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mxyztplk333Author Commented:
Thank you for your replies.  Basically, it's just a floating div with one Flash object&embed tags.  I know how to attach this Div to the document body in Firefox, but I don't know how to manipulate the DOM in IE and append this div to the top window BODY tag.  Please let me know if you can provide some insight.  

Lakio, would you still find the firefox screenshot helpful after my clarification?   Thanks for all your help.
0
 
LakioCommented:
I made a small page, try it and tell me if thats want you want or/and send me a screenshot ;)

.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Lakio made this</title>
	<script>
 
	function createDomElement( tag, where, text ) //  createElement ( 'div', document.body, 'The text in the div',  'Attribute1', 'Attribute1value',  'Attribute2', 'Attribute2value',  'Attribute3', 'Attribute3value'..... and so on )
	{
		with(document)
		{
			var element = createElement( tag );
			var a = arguments;
			
			for( var i=3; a[i]; i++ )
			{
				element.setAttribute( a[i++], a[i] );
			}
 
			text && element.appendChild( createTextNode(text) );
			where.appendChild( element );
			return element;
		}
	}
	
	function addSuperDiv( linkElm )
	{
		var element = createDomElement( 'div', document.body, 'The text in the div asdf asdfasdf asdf asdfa sdf ',  'id', 'superDiv', 'style', 'position:absolute; background:blue; top:80px' );
		element.style.left = '40px';
		
		linkElm.parentNode.removeChild( linkElm ); // deletes the link
	}
 
	</script>
</head>
<body>
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
	qwertyuiopðasdfghjklæ´zxcvbnm,.<br />
 
	<a href="#" onclick="addSuperDiv(); return false">TEZT</a>
</body>
</html>

Open in new window

0
 
LakioCommented:
I forgot "this":
<a href="#" onclick="addSuperDiv( this ); return false">TEZT</a>
0
 
UnderSevenCommented:
Have you tried putting a z-index on it to make it independent of the rest of the page?
0
 
mxyztplk333Author Commented:
Thank you, Lakio!  I really appreciate your help on this.
0
All Courses

From novice to tech pro — start learning today.