John P. New

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJohn P. New
ToMe
SubjectHow to check if a document has completely loaded in a newly created window?
Date9 July 2004 20:24
Hi,

First off, I'd like to congratulate you on a great site. It has taught
me a lot about cross-browser scripting and many other things.

Currently I am trying to open the contents of a frame in a new window,
change the lineHeight in that new window in order to be able to reduce
the page contents to print on a single page.

I am having trouble referencing the lineHeight property in the new
window

I open the new window with:

new_window =
window.open(top.frame1.location,'window','width=400,height=200...<snip>...')

Then, from the opening window, I try to change the lineHeight with:

new_window.document.getElementById('data').style.lineHeight =
_linespacing

where _linespacing is a value from a text box, and the <tbody> element
of a table in new_window is labelled id="data".

The problem I am having is that the contents of the new_window are not
loaded by the time the lineHeight is being set. If I put an alert()
statement between the above two statements, the window has enough time
to load and the lineHeight property is set properly.

Is there a good cross-browser way to detect if new_window has fully
loaded before applying the lineHeight? I have tried a couple of
approaches, but nothing has worked yet.

Any suggestions?

Thanks in advance,

John P. New
FromMe
ToJohn P. New
SubjectRe: How to check if a document has completely loaded in a newly created window?
Date9 July 2004 21:37
John,

sure. get the new window to do it for itself.

in the new window, use the following

<body onload="if(window.opener&&typeof(opener._linespacing)!='undefined'){
document.getElementById('data').style.lineHeight = opener._linespacing;}">

That should take care of itself. The script will only run if it is opened
in the new window, and it will check for the new line spacing and apply it
automatically.

If this is not practical (if you cannot change the content of that page),
it is possible to do this without having to do so, but it is a little bit
more complicated (running a timer and continually checking until you have
access to the element) - let me know if you need this, because I should be
able to write it for you.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJohn P. New
ToMe
SubjectRe: How to check if a document has completely loaded in a newly created window?
Date9 July 2004 22:26
Tarquin,

Thanks so much. I was trying to check the existence of something in the
new window from the opening window, rather than the other way around, as
you have suggested. Your code works perfectly.

Thanks for your help and keep up the good work,

John
FromJohn P. New
ToMe
SubjectQuerying frameset cols/rows value in IE4 and IE5
Date16 July 2004 05:00
Hi Tarquin,

Thanks again for that last snippet of code; it's working well.

I have another (hopefully) quick question for you. I am trying to query
the cols and rows value of a frameset with document.all['frame_id'].cols
and document.detElementByID('frame_id').cols (using the detection method
on your site) after the frameset has been resized.

In Mozilla and IE5.5+, the query returns the current state of the .cols
or .rows value, which is the behaviour I want. However, In IE4 (using
document.all) and 5 (using getElementById), querying those values
returns the original values, regardless of the current state of the
frameset.

Is there a simple workaround for this, or is there another property of
which I am unaware? Is this a bug or a 'feature'?

If you need more info, let me know. Thanks in advance,

John P. New
FromMe
ToJohn P. New
SubjectRe: Querying frameset cols/rows value in IE4 and IE5
Date16 July 2004 09:15
John,

I believe this is a feature (in fact, I believe that Mozilla/IE5.5 are
wrong here, since a viewer changing the frameset should not modify the DOM
of the document, but I can see why they chose to use that behaviour). I
notice that Opera 7.5, Safari 1.2, Internet Explorer/Mac and ICEbrowser
still follow the older (correct but less useful) way. (Remember, of course,
that IE and Netscape/Mozilla are not the only browsers around). ICE also
insists that you correctly use getAttribute, and not just 'cols' or 'rows'
- Virtually no-one actually uses ICE so it is a simple matter of 'do I care'
... well, the script below takes care of it for you :)

The only cross browser (including the older browsers) way to check on this
is to check the actual size of the pages within the frameset. If you want
to go to this effort, this is how you would do it:
check if the frameset in question uses rows or cols
step through the frames collection and check the relevant width or height
of each page
This will _only_ work with basic frameset layouts, where all frames
contained directly in the page are within the same frameset tag, not nested
framesets.

function getSizeOf(oFrame,oDim) {
 if(oFrame['inner'+oDim]) {
   return oFrame['inner'+oDim]; }
 oFrame = oFrame.document;
 if(oFrame.documentElement&&oFrame.documentElement['client'+oDim]) {
   return oFrame.documentElement['client'+oDim]; }
 if(oFrame.body&&oFrame.body['client'+oDim]) {
   return oFrame.body['client'+oDim]; }
 return 0;
}

var d = document;
var isCols = d.all ? d.all['frame_id'] : d.getElementById('frame_id');
isCols = isCols.getAttribute ? isCols.getAttribute('cols') : isCols.cols;
isCols = isCols ? 'Width' : 'Height';
for( var x = 0, f, oAttr = ''; f = document.frames[x]; x++ ) {
 oAttr += (oAttr?',':'') + getSizeOf(f,isCols);
}

alert(oAttr);


Tarquin
FromJohn P. New
ToMe
SubjectRe: Querying frameset cols/rows value in IE4 and IE5
Date17 July 2004 00:55
Tarquin,

Thanks again. I thought I might have to use the actual frame sizes, but
I wanted to check; plus, your code is much more elegant than mine would
have been. You make a good argument for Mozilla/older IE behaving
incorrectly.

I hadn't checked in other browsers yet because obviously my current
approach wasn't working. Currently I am using various Mozilla versions
on Windows and Linux, IE from 4 to 6 and Konquerer 3.x (which I believe
is the basis of Safari). I haven't installed Opera yet, but I plan to
shortly under both Linux and Windows. I don't have access to a Mac (and
VMWare doesn't do Mac), so I'm out of luck there. Before I found your
site, I hadn't even heard of ICEbrowser, so I may not test with it. For
the work I am doing currently (porting an old British Parts List to the
Web and CD-ROM), I hadn't thought of checking with any text-based
browsers, because the illustrations of exploded parts diagrams are so
integral to the site; I may revisit that assumption.

John
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.