Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > What could cause scrollWidth to return 0?

Reply
Thread Tools

What could cause scrollWidth to return 0?

 
 
Robert Oschler
Guest
Posts: n/a
 
      09-06-2003
I have a "child" document that I use for an IFRAME element that I put into
several "parent" documents. These "parent" documents therefore contain the
IFRAME whose SRC property is set to the "child" document.

The parent(s) have three Javascript functions, here they are:

// =============================

var gMargin = 5;

function getScrollWidth(doc, callerId)
{

if (true)
{
// If no document reference was passed, assume it is the
// current document.
if (!doc)
doc = document;

var ret;

if (doc.all)
{
// Internet Explorer.
if (doc.compatMode &&
doc.compatMode != 'BackCompat')
ret = doc.documentElement.scrollWidth + gMargin + 'px';
else
ret = doc.body.scrollWidth + gMargin + 'px';
} // if (doc.all)
else if (doc.width)
// Other browsers.
ret = doc.width + gMargin + 'px';

// alert('(getScrollWidth) Returning scroll width(' + ret + ') to
caller Id: ' + callerId);

return ret;
} // if (true)
}

// =============================

function getScrollHeight(doc, callerId)
{
if (true)
{
// If no document reference was passed, assume it is the
// current document.
if (!doc)
doc = document;

var ret;

if (doc.all)
{
// Internet Explorer.
if (doc.compatMode &&
doc.compatMode != 'BackCompat')
ret = doc.documentElement.scrollHeight + gMargin + 'px';
else
ret = doc.body.scrollHeight + gMargin + 'px';
} // if (doc.all)
else if (doc.height)
// Other browsers.
ret = doc.height + gMargin+ 'px';

// alert('(getScrollHeight) Returning scroll height(' + ret + ') to
caller Id: ' + callerId);

return ret;
} // if (true)
}

// ---------------------------------------------------------------

function getScrollHeight(doc, callerId)
{
if (true)
{
// If no document reference was passed, assume it is the
// current document.
if (!doc)
doc = document;

var ret;

if (doc.all)
{
// Internet Explorer.
if (doc.compatMode &&
doc.compatMode != 'BackCompat')
ret = doc.documentElement.scrollHeight + gMargin + 'px';
else
ret = doc.body.scrollHeight + gMargin + 'px';
} // if (doc.all)
else if (doc.height)
// Other browsers.
ret = doc.height + gMargin+ 'px';

// alert('(getScrollHeight) Returning scroll height(' + ret + ') to
caller Id: ' + callerId);

return ret;
} // if (true)
}

// ---------------------------------------------------------------



In the "onload" event of the "child" document, a call is made to a function
call in the "parent"'s Javascript like this:

<BODY onload="parent.resizeIFrame(document, parent.getScrollWidth(),
parent.getScrollHeight(), 'test');" >
.... // rest of HTML
</BODY>


causing the "parent" document to resize the IFRAME to the scrollWidth and
scrollHeight of the "child" document. It works great on one "parent"
document, but on another I get 0 for the "child" document's scrollWidth and
scrollHeight properties.

What could cause this?

BTW, Testing is being done with Internet Explorer 6.x.

thx

--

Robert Oschler


 
Reply With Quote
 
 
 
 
Robert Oschler
Guest
Posts: n/a
 
      09-06-2003
I accidentally duplicated the getScrollHeight() function call and forgot the
resizeIFrame() function call, here is the latter:

function resizeIFrame(id, x, y, callerId)
{
var SX = "";
var SY = "";

if (true)
{
SX = x + '';
SY = y + '';

if (SX.indexOf('px') == -1)
SX = SX + 'px';

if (SY.indexOf('px') == -1)
SY = SY + 'px';

// alert("(resizeIFrame), called by '" + callerId + "'> id = " + id
+ ", x = " + x + ", y = " + y);

var iframeElement = null;

// alert("(resizeIFrame) set iframeElement to null.");
if (top.document.all)
{
// Internet Explorer.
// alert('(resizeIframe) IE browser.');
iframeElement = top.document.all[id];

} // if (document.all)
else if (top.document.height)
{
// Other browsers.
// alert('(resizeIframe) Non-IE browser.');
iframeElement =
top.document.getElementById(id);
} // else if (top.document.height)

if (iframeElement)
{
iframeElement.style.width = x;
iframeElement.style.height = y;
// alert("(resizeIFrame) iframeElement.style (width, height) = "
+ iframeElement.style.width + ", " + iframeElement.style.height);
}
else
alert('(resizeIFrame) iframeElement is null for id = ' + id);
} // if (true)
}

// ---------------------------------------------------------------


--

Robert Oschler


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
node.offsetWidth vs clientWidth vs scrollWidth liketofindoutwhy Javascript 5 04-24-2008 10:30 AM
scrollWidth mystery =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 0 09-16-2006 12:55 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
will all these messages cause a problem . I am a new subscriber and my computer is downloading 100,000 messages. Will this cause any kind of a problem with my ability to store other items?? Camille White Camille White Computer Support 9 11-08-2004 01:13 AM
What could cause left open SQL data connection =?Utf-8?B?UGF1bA==?= ASP .Net 6 04-05-2004 06:01 PM



Advertisments