Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window.close() -- simple question for the experts.

Status
Not open for further replies.

netjkus

Programmer
Aug 25, 2003
2
US
Here is a quick question.. for Javascript Experts.

I have a JS code that opens an about::blank IE window.
I close this new window opened if the parent window is about to close,using window.close() in onunload (or onbeforeunload) it will get closed!

But if I push the contents of PDF in aspx file, it will not close the window with the same logic.. Here is my code example.
------------
Parent file : (parent.aspx script)


<script type="text/javascript" language="javascript">

var pdf_window = null;

function OpenFormPdfViewer(user_form_id)
{
CloseFormPdfViewer();

pdf_window = window.open("sample.aspx");

if ( pdf_window != null )
{
document.all["ButtonNext"].disabled = false;
this.focus();

}
}


function closeIt()
{
if ( pdf_window != null)
{
alert('Closing Child window');
pdf_window.close();
pdf_window = null;
}
}

function CloseFormPdfViewer()
{
closeit();
}

window.onbeforeunload = function(){closeIt();}

</script>


This will close the new browser if I navigate out of this page: but if I change the
pdf_window = window.open("sample.aspx");
to
pdf_window = window.open("viewformpdf.aspx?f=100");
to open a PDF file in the new IE browser, the same logic to close will not work.

here is my viewformpdf.aspx code (part of it):
---------------

byte[] bytes = GetFormPdf(m_user_form_id);

Debug.Assert(bytes != null);

if ( (bytes != null) && (bytes.Length > 0) )
{
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "inline");
Response.BinaryWrite(bytes);
Response.End();
}

---------------
Am I missing something?!? this will not work if I try to open any text file in a new window as well.
---------------

I am not sure why it will work for any normal page while not on PDf/txt !?!

Thanks for the help!
Jay
 
I had the same problem when I used a parent window to open a new window with Google in it. I then tried to use the parent window to simply move or resize the new window, but it wouldn't let me. I found that if I did the resizing and moving first, THEN pointing the window to Google, it was fine.

However, that won't help you here. What I suggest you try is create a window with an iframe of width="100%" and height="100%" and source that to your PDF. You might have trouble with scrollbars (which you can maybe fix with tag attributes or CSS), but you might be able to maintain close-functionality over the window from the parent.

'hope that helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top