Click to See Complete Forum and Search --> : How to see if loaded?


Chrille
06-29-2003, 04:10 AM
Hi people,

This is my problem:

I have two frames, externalContent and bar.
In bottom I have a bar, and in top I want to view an external website.

My problem is that in the bottom bar I want to view a progress bar until the external webpage has been loaded.

This is what I got so far:



var timerId = 0;
var numSecs = 0;

function start()
{
timerId = setTimeout("updateChecker()",100);
}

function updateChecker()
{
numSecs += 100;

if(timerId)
{
clearTimeout(timerId);
timerId = 0;
}

if(numSecs>8000) // Just delay at the moment
{
document.getElementById("loading").style.visibility = "hidden";
document.getElementById("progressBar").style.visibility = "hidden";
}
else
{
timerId = setTimeout("updateChecker()",100);
}
}



Is there any way to access the source code of the external document? If so, I could view the progressbar as long as document.indexOf("</html>") == -1

Do you have any other solution to this problem?

Thanks in advance

Regards,
Chrille

SlankenOgen
06-29-2003, 07:31 AM
Just use <body onload = "functionName()">

Charles
06-29-2003, 08:21 AM
JavaScript will not let you play around with other people's web sites. It's a security thing.

You'll need to use some kind of server side script to get the file and then send it to the user so that it looks like the file is yours. And so that the images and links on that page work you will need to parse the document, look for a BASE element and provide one if it doesn't exist. The Perl version would look something like:

#!user/local/bin/perl
use CGI qw(header param);
use LWP::Simple;
use HTML::TreeBuilder;

my $tree = HTML::TreeBuilder->new;

$tree->parse (get param 'url');
$tree->eof;

$tree->find_by_tag_name('head')->push_content(HTML::Element->new('base', href => (param 'url'))) unless($tree->find_by_tag_name('base') && $tree->find_by_tag_name('base')->attr('href'));

print header, $tree->as_HTML();

That example needs a little work yet so that the HTTP headers are properly passed along, but you get the idea.

Chrille
06-29-2003, 12:25 PM
Oh, okey. Thanks for the script!

Regards,
Chrille