Hi there!
I've created a "message" box that consists of a <div> with a bunch of information in it and some buttons (which could be "ok", "yes", "no", "cancel"... ). It's dynamically created with some .NET code on the server.
Because the message information that is within this <div> is dynamic, it can be several lines long...also the message box <div> can be variable widths wide as well. Therefore, I need a Dependable way to dynamically retrieve the width and height of the <div> in order to properly center it in the middle of the browser.
I have used:
[code=javascript]
var panelHeight = document.getEle mentById(nameOf MessageBoxWindo w).clientHeight ;
var panelWidth = document.getEle mentById(nameOf MessageBoxWindo w).clientWidth;
[/code]
However this code only seems to work in certain circumstances, and others doesn't work at all (using firebug I discovered that these two values were always 0 for some weird reason).
In order to find the width of the <div>, I set the <div>'s style width dynamically with my .NET code and then used the following code:
[code=javascript]
var styleWidth = panel.style.wid th;
var panelWidth = Number(styleWid th.replace(/px/,""));
[/code]
This works, however it feels like a bit of a "workaround " to me. Also, this solution doesn't help me find the height of the <div>.
Does anyone know what might be the cause to the element.clientW idth to always be 0?
Does anyone know of another way to dynamically determine the height and width of the <div>?
Thanks for your time,
-Frinny
I've created a "message" box that consists of a <div> with a bunch of information in it and some buttons (which could be "ok", "yes", "no", "cancel"... ). It's dynamically created with some .NET code on the server.
Because the message information that is within this <div> is dynamic, it can be several lines long...also the message box <div> can be variable widths wide as well. Therefore, I need a Dependable way to dynamically retrieve the width and height of the <div> in order to properly center it in the middle of the browser.
I have used:
[code=javascript]
var panelHeight = document.getEle mentById(nameOf MessageBoxWindo w).clientHeight ;
var panelWidth = document.getEle mentById(nameOf MessageBoxWindo w).clientWidth;
[/code]
However this code only seems to work in certain circumstances, and others doesn't work at all (using firebug I discovered that these two values were always 0 for some weird reason).
In order to find the width of the <div>, I set the <div>'s style width dynamically with my .NET code and then used the following code:
[code=javascript]
var styleWidth = panel.style.wid th;
var panelWidth = Number(styleWid th.replace(/px/,""));
[/code]
This works, however it feels like a bit of a "workaround " to me. Also, this solution doesn't help me find the height of the <div>.
Does anyone know what might be the cause to the element.clientW idth to always be 0?
Does anyone know of another way to dynamically determine the height and width of the <div>?
Thanks for your time,
-Frinny
Comment