One idea: instead of setting the src to point to the PDF file directly, set it to point to a page that will load the pdf; e.g. http://example.com/getPdf.aspx?file=SOME_URI
The getPdf.aspx page can contain code that detects when the page is about to navigate and then perform some action. I would suggest that it calls the parent page which should first close the iframe and the navigate to the PDF.
Something like the following:
//In getPdf.aspx
function Navigate()
{
var parentWindow = this.parentNode.parentNode //this.parentNode.parentNode is the window hosting the iframe;
var parentWindow.CloseMe(this.parentNode, PDF_URI); //this.parent is the Iframe
}
window.onunload = Navigate;
//In main page
function CloseIt(window_to_close, pdf)
{
window_to_close.close();
window.navigate(pdf); // or window.location = pdf;
}
I haven't tested this but something very much like it might work. You might get a message warning that the script is trying to close the page or something.