• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

document variable is nullified after servlet file download

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I started using a global variable defined in an external script to refer to the document:



This was due to a problem with the 'document' variable on a JSP becoming nulled out (supposedly) after a File/Save As box was displayed. I found that storing the document handle to the global variable fixed this.

And everything seemed to work fine, until...

One client machine is having an issue with a JSP that links to the external .js. Bringing in the script seems to fail on the global variable declaration, and so any calls to methods in the file are throwing errors.

Is this bad practice? Any idea what settings on the lone client machine we see this need to be checked? I've verified we're using the same version of IE, security settings seem ok, etc.

thanks,
Tom
[ December 03, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem with applying band-aids is that they create problems that require other band-aids that create problems that require more band-aids that...

and you end up with something held together by chicken wire, bubble gum and duct tape that is fragile and falls apart if you breath near it.

My advice is to solve the real problem and pursue the "document gets nulled" issue and find out what's up with that. I've never heard of such an issue.

By the way, the JSP-ness of your page is moot. Once it gets to the browser, it's just HTML.
[ December 03, 2007: Message edited by: Bear Bibeault ]
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks for the advice.

So storing the document variable globally == bad idea then? Is it better to use the 'document' variable itself in the external .js file? I want to rip off the bandaids, but I want to make sure I'm heading in the right direction.

The document is null issue went something like this:

Button page would call servlet that would stream a file back to the client machine, prompting a save as dialog:



This all worked fine, but afterwards, from the same page, any other javascript commands referencing the document would fail. I assumed something was happening to 'document' handle because of the file/save as dialog.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, you didn't mention a servlet. I'll forward this on to the servlets forum with a suitable topic title change.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks... yes, the file download issue is servlet-related...

Any chance you could address my questions about javascript 'document' handle?



So storing the document variable globally == bad idea then? Is it better to use the 'document' variable itself in the external .js file? I want to rip off the bandaids, but I want to make sure I'm heading in the right direction.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tom Katz:
Any chance you could address my questions about javascript 'document' handle?


Yes, holding an alias to browser resources is a very bad idea. If the document handle is getting nullified that means that the browser has determined it's no longer necessary ("why" is a question for people more familiar with what happens during an attachment download). Holding a reference to it behind the browsers back is unlikely to lead to good things.

Generally, if you've got to do something weird to get something to work, chances are it's going to cause other troubles.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gotcha, thanks again!

I wasn't sure if it was weird, using global references like that in a global script . . .
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Global variables are generally to be avoided when possible, but holding references to browser resources beyond the time when the browser thinks that they're active is never a good idea.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm...
I haven't seen this problem before and we have plenty of pages with links that download things.

Right now, I don't have access to a machine with MSIE but these two pages work in Firefox.

page1.html


download.jsp


Here's what I did:
1.) drop both pages into the ROOT directory of Tomcat.

2.) Point browser to http://localhost:8080/page1.html

3.) Click the link that says "click me" and note that the popup says "Hello There" (which is the document.title)

4.) Click on the 'download a file' link and save the file.

5.) Click the "click me" link again.

Even after clicking a link that makes a new request and receives a response but doesn't redraw the screen, the code in the "click me" link is still able to locate document.title. Can run this same test in the browser that you're having trouble with?
[ December 04, 2007: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried again but, this time with a form that calls the download page instead of a hyperlink.
Same results.




I don't see how this could be anything but a browser issue.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the time has come for you to code up a minimal example that demonstrates the issue so we can try to recreate it in our own environments.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I will get something together (once I'm back on my work 'puter).

This was pretty easily recreatable in IE6, and just today I upgraded my work machine to IE7 and couldn't get it to happen.

Thanks for the information/tips. If I can recreate it, I will post the relevant code.

ByTheWay: I got rid of all that global javascript variable funkiness.
reply
    Bookmark Topic Watch Topic
  • New Topic