By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Javascript popup window question

P: 31
All,

I am using javascript (window.open()) to create a popup to do some processing. This popup is going to create a PDF which can take anywhere from 10 secs to 2 mins (alot of backend SQL calls) and I was hoping to use this popup to show the user that something is going on (animated gif) and give them the ability to use the parent window to do other things in our system (while the popup is creating the PDF on the server).

My problem lies in the fact that while the popup is creating the PDF, the parent window cannot navigate to other pages (until the popup window is done). Is there any way to disassociate the popup window with the parent window so a user will be able to navigate with the parent window while the popup window is processing?

Thx
jonpfl
Jul 17 '08 #1
Share this Question
Share on Google+
18 Replies


gits
Expert Mod 5K+
P: 5,343
you could send an AJAX-call and just open the window when the server sends the response ... this is done in the onreadystatechange-callback - first just have a look at a basic AJAX-example and ask more questions about it when you have them :)

kind regards
Jul 17 '08 #2

P: 31
I have never used ajax before.

Is there a way to do with just javascript or am I going to have to get ajax?

Thx
jonpfl
Jul 17 '08 #3

gits
Expert Mod 5K+
P: 5,343
AJAX is just javascript ;) ... by making use of the browsers XMLHttpRequest and its asynchronous behaviour ... with that you could achieve what you want ...

kind regards
Jul 17 '08 #4

P: 31
AJAX is just javascript ;) ... by making use of the browsers XMLHttpRequest and its asynchronous behaviour ... with that you could achieve what you want ...

kind regards
Ok, let me get this straight.

If I incorporate Ajax on my child/popup to create the PDF, my user is going to be able to go to the parent window and navigate to another page while the child/popup is awaiting a response from the server?

Sorry if this is a total newbie question but I am new at this.

Thx
jonpfl
Jul 17 '08 #5

gits
Expert Mod 5K+
P: 5,343
not exactly ... basicly you start a async XMLHttpRequest and say: open the window when you are ready ... the user may do whatever he wants in the meantime ...
Jul 17 '08 #6

P: 31
not exactly ... basicly you start a async XMLHttpRequest and say: open the window when you are ready ... the user may do whatever he wants in the meantime ...
Now that you tell me this, I think I might want to do it another way (tell me which ones are feasible)

1) User is on page1.asp and clicks a button to create a PDF. I use javascript to send an async call to the server to start creating the PDF (it is all vbscript with a bunch of stored procs). While the PDF is being created, I assume the user can navigate to page2.asp and do something else, correct? I was thinking that instead of using a popup window when completed, I could just email them the PDF using vbscript on the server. Does this sound doable? I assume I do not actually have to have a callback function, right?

2) If I decide to use a popup window and user makes the request on page1.asp and has now changed to page2.asp, how would I handle that? I assume every possible page the user could navigate to in our internal app, I would have to have that callback function declared in the javascript, right? We currently have an include file called common.asp that I could it in since all our pages include that.

Is there a specific version of Ajax you recommend for ASP? Right now, I am reading up on one called "Sarissa"

Thx
jonpfl
Jul 17 '08 #7

gits
Expert Mod 5K+
P: 5,343
i think your first version sounds quite good ... but to clarify something: the callbackfunction is passed to the requestobject itself ... it mustn't be declared on every page ... and there is nothing like an ajax-version or something similar ... it is just javascript and xml and an instance of the XMLHttpRequest-Object of a browser ... there are just some frameworks out there that encapsulate the usage of all of this ...
Jul 17 '08 #8

P: 31
i think your first version sounds quite good ... but to clarify something: the callbackfunction is passed to the requestobject itself ... it mustn't be declared on every page ... and there is nothing like an ajax-version or something similar ... it is just javascript and xml and an instance of the XMLHttpRequest-Object of a browser ... there are just some frameworks out there that encapsulate the usage of all of this ...
Ok, I put some ajax in my javascript code

Expand|Select|Wrap|Line Numbers
  1.             http_request = new XMLHttpRequest();
  2.             sURL = "ReportHeading=" + frmCreditReport.ReportHeading.value;
  3.             sURL += "&MeetingId=" + frmCreditReport.MeetingId.value;
  4.             http_request.onreadystatechange = jon;
  5.             http_request.open('POST', "popup_pdf.asp?" + sURL, true);
  6.             http_request.send(null);
  7.  
  8. function jon()
  9. {
  10.     if (http_request.readyState == 4)
  11.     { 
  12.         alert(http_request.responseText);
  13.     } 
  14. }
  15.  
And I can see that the PDF is getting created (I save it to a temp directory) but I still have the problem of not being able to navigate to another page. When I try to change to another page, my page waits until the Ajax is complete before continuing.

What am I doing wrong?

Thx
jonpfl
Jul 17 '08 #9

gits
Expert Mod 5K+
P: 5,343
is it a large pdf? ... what if you just alert a string like 'foo'? may be the problem is the transfer of the response data and not the pdf-creation at all? presenting a download-link or send it per mail as you already suggested would workaround that?
Jul 17 '08 #10

P: 31
is it a large pdf? ... what if you just alert a string like 'foo'? may be the problem is the transfer of the response data and not the pdf-creation at all? presenting a download-link or send it per mail as you already suggested would workaround that?
Yes, it is a very large PDF

I cannot email it because I would have the same problem. When I am in the processing of creating it (~ 1 min), I cannot navigate with the calling window to other pages. Is there a way to do that?

IE : I am on an asp page and a user clicks a button to create a PDF. I send that request to the server for prcoessing. This process can take upwards of 2 mins and I want the user to be able to navigate to other pages while the PDF is being created. If I try to navigate away from the page that made the PDF request (in this case, via Ajax), it just hangs until the PDF creation process is completed.

Thx
jonpfl
Jul 17 '08 #11

gits
Expert Mod 5K+
P: 5,343
did you try the 'foo'-alert? ... in your case it seems to be a good idea to start the request, and update the page with a link to the created file at the server in the callback and let the user decide to download it ... this will typically be done with the browsers download-manager ... could that be an option? as i said ... the browser doesn't wait for the request, i guess he waits for the pdf-data transfer ...

kind regards
Jul 18 '08 #12

P: 31
did you try the 'foo'-alert? ... in your case it seems to be a good idea to start the request, and update the page with a link to the created file at the server in the callback and let the user decide to download it ... this will typically be done with the browsers download-manager ... could that be an option? as i said ... the browser doesn't wait for the request, i guess he waits for the pdf-data transfer ...

kind regards
Actually, I changed the callback function to a 'foo'-alert. I now see what is going on. If I start the request and it is processing in the background and I try to go to another website (ie www.google.com), it lets me (and I assume the request to call the callback function is disregarded by the browser). BUT, if I try to navigate inside my webpage using the menu system someone else devised, it does not allow me to change pages.

Any idea why?

Thx
jonpfl
Jul 18 '08 #13

gits
Expert Mod 5K+
P: 5,343
hmmm ... is the page-menu responding in any way? does it reload the window onclick? in case the window is reloaded then i think the current request will be aborted ... do you have a testpage online, so that i could have a deeper look at it?
Jul 18 '08 #14

P: 31
hmmm ... is the page-menu responding in any way? does it reload the window onclick? in case the window is reloaded then i think the current request will be aborted ... do you have a testpage online, so that i could have a deeper look at it?
I wish I had a test page online but this is all internal work at the moment. I do notice that if I am creating a PDF on the server, I can enter an URL for another part of our system w/o using the menus and it works. If I try to navigate with our menus to the same page, it doesn't work.

I have a feeling something in our menuing system is funky and needs to be looked at. I can put the code up here if you want to look at it (I am fairly new at this stuff so alot of it doesnt make sense to me)

Thx for all your help to this point. You have been very helpful!!!
Jul 18 '08 #15

P: 31
hmmm ... is the page-menu responding in any way? does it reload the window onclick? in case the window is reloaded then i think the current request will be aborted ... do you have a testpage online, so that i could have a deeper look at it?
Actually, I looked at the page some more and noticed the menu system is using <a href'=""> all over the place. I tried putting a <a href="">click here</a> on my page and while the PDF was being created, I clicked on the text and the page would not change until the PDF was created. I could manually put the same URL in browser and submit it while the PDF was being created and it worked fine.

Thx
jonpfl
Jul 18 '08 #16

gits
Expert Mod 5K+
P: 5,343
does it work with:

Expand|Select|Wrap|Line Numbers
  1. <span onclick="window.location.href='http://www.google.com'">click me</span>
kind regards
Jul 18 '08 #17

P: 31
does it work with:

Expand|Select|Wrap|Line Numbers
  1. <span onclick="window.location.href='http://www.google.com'">click me</span>
kind regards
Yes, it works with that but if I try to put a URL in within our internal web app, it doesn't change until the PDF is created. I am starting to wonder if this is some sort of limitation on Ajax

Thoughts?
Jul 18 '08 #18

gits
Expert Mod 5K+
P: 5,343
could you try it with firefox and install the firebug extension? then have a look at its errorconsole where we might see what error occurs and find out where the problem might be ... i'm not aware of any problem that you describe ... we use the pdf-creation in the same systematic way as you i told you without problems.

kind regards
Jul 19 '08 #19

Post your reply

Sign in to post your reply or Sign up for a free account.