473,221 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

javascript document.location to download a file

247 Expert 100+
hey all,

i have another problem. basically the question is: how do i make sure a file is downloaded instead of opened?

but i'll explain the situation. i'm trying to download a file using a button. when clicked, i call an ajax-request to a php-page where i dynamically create a ".pmp"-file. then it returns the name of the file. last, i open the file using document.location.

here is my ajax request and the code to redirect my page.
Expand|Select|Wrap|Line Numbers
  1.             function Exportfile(){
  2.                                 var data = "--- content of 'a lot of data' goes here ---";
  4.                 XMLHttpRequestObject = GetXmlHttpObject();
  5.                 var sended = "data="+data;
  6.                 var download = "download.php";
  7.                 XMLHttpRequestObject.open("POST",download,true);
  9.                 XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  10.                 XMLHttpRequestObject.setRequestHeader("Content-length", sended.length);
  11.                 XMLHttpRequestObject.setRequestHeader("Connection", "close");
  13.                 XMLHttpRequestObject.onreadystatechange = function(){
  14.                     if (XMLHttpRequestObject.readyState == 4){
  15.                         filename = XMLHttpRequestObject.responseText;
  16.                         document.location = filename;
  17.                     }
  18.                 }
  20.                 XMLHttpRequestObject.send(sended);
  21.             }
does anyone know how i can do this?
May 8 '09 #1
1 12747
247 Expert 100+
never mind. i found a solution on the last page of my search on the forum. i was attracted to the number of views.

anyway, here is what you need to do
May 8 '09 #2

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

Similar topics

by: John Taylor-Johnston | last post by:
This will give me the source of the current page. <a herf="javascript:document.location = 'view-source:'+document.location">testpage.htm</a> I want to display the source of another page, using...
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
by: yogesh.bhardwaj | last post by:
Hello all I am trying to modify the link URL when a user clicks on the link. Following is the code: <a onClick="document.location.href=modifyURL(this.href);" href="SOME_DYNAMIC_URL"...
by: John | last post by:
I have some code that changes a PDF file in another frame using: parent.frame.document.location.href = "PDF File" This code works fine the first time it is called. But if a PDF file is in that...
by: Graham | last post by:
I'm not very experienced with Javascript, and I'm trying to determin a current web page's path. If I use document.location, it returns http://domain.com/path/to/file I only want to see...
by: cephelo | last post by:
I'm trying to incorporate the document location into a basic XSL transformation on the client-side (Firefox and IE primarily). Currently I hack it in using Javascript.. hardly ideal. Is there a...
by: itmanager8815 | last post by:
I had a question regarding the use of document.location. I have the following script: <HTML> <BODY> <SCRIPT LANGUAGE=JAVASCRIPT> window.status=''; ...
by: DNK2007 | last post by:
Hi all Look at the following code <html> <head> <script type="text/javascript"> document.location="http://www.gmail.com"; alert(document.location); </script>
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.