It is impossible to reference to the document object of a frame if a page has failed to load. You will only get an "Access Denied" error if you try to do document.frames.frame.document .
JavaScript isn't allowed to do anything to a page that doesn't belong to the site it was started on.
Also, it is not good practice to use give a name attribute to a a tag and reference it directly. That will only work in Internet Explorer. Do document.body.frame instead or give the tag an id="frame" attribute and reference to it using document.getElementById('frame').