views:

32

answers:

1

Hi,

I have a an iframe that has a report within it. What I also have, is a feature to allow the user to detach the report within the iframe and open it up in it's own window, using window.open() call.

My problem is, when I press on the detach button, the whole report that initially loaded in the iframe actually goes through the motions of re-running the query again and so presents the user with a white screen until the report eventually renders again.

Is there anyway of not re-running the report in the detached window or somehow grabbing a cached version?

Thanks.

+1  A: 

If you already have the HTML on the client side, you can write that to the popup window without going to the server.

    var w = window.open(); 
    w.document.write("Text in new Window"); 

That will open a window and write some text to it. All you need to do now is get the content from your iframe and write it to the new window. Bingo :)

BTW IMO: Opening new windows in browsers should be avoided where possible as many browsers block it and most automated UI testing tools don't support it.

EDIT (in response to comment):

Here is an example of reading from and writing to an iFrame using the jQuery JavaScript library.

    // Write to
    $("iframe").contents().find("body").html("Test Html")

    // Read from
    alert($("iframe").contents().find("body").html());

This basically finds iframe elements in the document and reads and write content to them. If your not using a JavaScript library I highly recommend learning up and using one of them.

BTW: My advice on popup windows also holds for iframes. You should avoid using them where possible.

tarn
thanks tarn - just wondering if you could pls provide some suggestions on how to grab the content from my iframe?
tonsils
updated answer, pls accept and up-vote if it helps :)
tarn
thanks tarn - will try out your solution and come back to you if that's ok.
tonsils