faqts : Computers : Programming

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 18 people (78%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I give a user an option to either download a file to the Hard drive orOpen the file javascrit

Mar 4th, 2005 03:07
TeraZen, sreeni chetty,


As far as I know, you can't force a user to download a file! JavaScript
is a restrictive language, that can "suggest" things to browser users,
but not force them!

Oops... I'm sorry! :) I didn't understand the question ;-) (was tired
this day :-P)

Just call a function that change the page location on the OnClick event
of a form button... Here's a sample code you can paste in a .html file;

<html>
<head><title>Test</title></head>
<script language="JavaScript">
<!-- Begin

function OpenFile() {
	window.location= 'http://www.domain.com/dir/file.ext';
}

//  End -->
</script>

</head>
<body>

<form name="myform">
<input type=button onClick="OpenFile()" value="Open File">
</form>

</body>
</html>