(JS) IE gets busted after download.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

(JS) IE gets busted after download.

Post by Heavy »

When I use this function:

Code: Select all

//JavaScript:
function DownloadFile(ID){
	document.location = 'file-download.php?ID=' + ID
}
...a dialog appears, which offers me ways to download the file. This works alright in both Mozilla and IE6.

Problem (with IE of course):
But when the file is downloaded and I move the mouse back to the page, eveything is broken and I get lots of JS-errors. The only immediate solution to the problem is to reload the page.

What gymnastics should I do to trick IE into working as expected, which is, to run the page continuously without errors, no matter how many times I click the download button?

This is because the page offers several downloads from a mysql database and I don't want users to have to reload the page after each download.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I might add:

I have browsed the msdn.microsoft.com for about an hour without getting anywhere.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

How do you call this function?
From a onClick or in a url?
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Code: Select all

<td class="buttontd"><img src="img/file-download.png" id="DownloadButton" border="0" title="Click to download" onclick="DownloadFile(ActiveID)" class="hoverbutton" ></td>
ActiveID is a JS-var that is set erlier, before the user sees this. As I said. It works in both IE and MZ, but whet the download is finished, IE just produces a mess of JS-errors.

I guess there is a way how things should be done. A way I'm currently not on...
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Maybe it has something to do with return values, but it's just a wild gues.

Can we see the whole content? Or a link to the real page.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Code: Select all

<body onmousemove="GetMouseCoords()" onload="InitPage()" id="Body"  >
and

Code: Select all

function GetMouseCoords()&#123;
	Now.X = window.event.clientX + document.getElementById('Body').scrollLeft
	Now.Y = window.event.clientY + document.getElementById('Body').scrollTop
	MovePopupInfo()
&#125;

function MovePopupInfo()&#123;
	if (IsFile)&#123;
		if (document.getElementById('PopupInfo_MoveFile') != null)&#123;
			document.getElementById('PopupInfo_MoveFile').style.left = (Now.X + 10) + 'px'
			document.getElementById('PopupInfo_MoveFile').style.top = (Now.Y + 10) + 'px'
		&#125;
	&#125;else&#123;
		if (document.getElementById('PopupInfo_Move') != null)&#123;
			document.getElementById('PopupInfo_Move').style.left = (Now.X + 10) + 'px'
			document.getElementById('PopupInfo_Move').style.top = (Now.Y + 10) + 'px'
		&#125;
	&#125;
&#125;
There is something more in the page related to the "body.keyup"-event. But as the page steps on its skirt without me pressing any keys, I left that out.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Okay, lets not fix the problem....

Change the
Img code to:

Code: Select all

<td class="buttontd"><A HREF="file-download.php?ID=<? echo $id ?>><img src="img/file-download.png" id="DownloadButton" border="0" title="Click to download" class="hoverbutton"></A></td>
Try this :o.

I think that the body onload not is triggert when you hit the back button to activate the window. And IE thinks you left the page, becouse the document.location.

PS: issen't that document.location.url = 'file.html';
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

PS: issen't that document.location.url = 'file.html';
Nope.

Code: Select all

//JavaScript:
function DownloadFile(ID){
   document.location = 'file-download.php?ID=' + ID
}
PHP opens a mysql connection and sends the content of a virtual file with identification number = ID.
As I told you. That part of everything works just fine. It is off the topic how the file is retrieved. It is on the topic whether the triggering function could or should be something else for getting IE to work properly.

I could workaround by doing this:

Code: Select all

//JavaScript:
function DownloadFile(ID){
   window.open('file-download.php?ID=' + ID,'popupwindowname')
}
But right now I am asking the world about specific instructions on how to do this the correct way, as fas as Microsoft is concerned.

As said before, I have searched the msdn network without finding the solution.
Last edited by Heavy on Mon May 05, 2003 9:48 am, edited 1 time in total.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

[]InTeR[] wrote: I think that the body onload not is triggert when you hit the back button to activate the window. And IE thinks you left the page, becouse the document.location.
Partly correct... Maybe.
I don't click any back button. I just move the mouse back to the page displayed.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

A correct way with M$?

Nope, can't do.

Aslong as it works, and the source is neath.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

IE tends to feel very buggy. Some bugs are real, some appear because of the web developer creating things out of spec. That doesen't mean MS lack of standards. They have just decided to go their own way.
By the way, I like very much the way that MS writes documentation (API docs). They have lots of cross-references and cover the topics pretty well.
Lack of such is the one of the few flaws of the Open Source Community. (Yeah, someone will blow me away for this. Admit it. Documentation could be better. But don't ask me do it, cause I am fed up with computers already. I do what I have to. The rest of my efforts go into music and electronics.)

Now... I am not even looking for a W3C-compliant way to preform that file download. (I have given up on that) But I am looking for the MS way to do is correctly.

Anybody?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I tried to reproduce the error but couldn't.
Maybe if you provide a working code snippet that causes such an error...
What are you trying to do?
I'm guessing you want to show something like a detail layer whenever the mouse is over a certain element. If so fetching the onmousemove event for the whole body might not be the best way.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I don't have the time for this right now, but here's (kind of) the error message:

"Permission denied"

What I do when the mouse moves is to reposition a table with the following style:

Code: Select all

table.popup &#123;
	background:rgb(255,240,220);
		border: 2px solid rgb(164,100,100);
		border-radius: 6px;
		-moz-border-radius: 6px;
	position:absolute;
		left:40px;
		top:100px;
&#125;
The table is hidden by default:

Code: Select all

<table class="popup" id="PopupButtons" style="display:none;" >
It works all the time except for when the following code has been executed in IE:

Code: Select all

function DownloadFile(ID)&#123;
   document.location = 'file-download.php?ID=' + ID
&#125;
I have worked around this for now, using the following instead:

Code: Select all

function DownloadFile(ID)&#123;
   window.open('file-download.php?ID=' + ID)
&#125;
Right now, this is a bigger problem...
Post Reply