TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Download Files Using Javascripts for Different Types of Browser
Bipin Patil
Jan 15
2016
Code
1.1
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
$scope.downloadDocument = function()
{
// Here we are passing URL from where we are going to download file to browser
var documentUrl =
{
'FileName'
: $scope.selectedRow[0].Url
};
// following method will give call to javascript method
Download($scope.selectedRow[0].Url)
};
function Download(url)
{
// Here we identifying browser
var isOpera = !!window.opera || navigator.userAgent.indexOf(
' OPR/'
) >= 0;
var isFirefox =
typeof
InstallTrigger !==
'undefined'
;
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf(
'Constructor'
) > 0;
var isChrome = !!window.chrome && !isOpera;
var isIE =
/*@cc_on!@*/
false
|| !!document.documentMode;
if
(isChrome || isFirefox)
{
var save = document.createElement(
'a'
);
save.href = url;
save.target =
'_blank'
;
save.download = $scope.selectedRows[0].Name;
var evt = document.createEvent(
'MouseEvents'
);
evt.initMouseEvent(
'click'
,
true
,
true
, window, 1, 0, 0, 0, 0,
false
,
false
,
false
,
false
, 0,
null
);
save.dispatchEvent(evt);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
}
if
(isIE) {
// Force downloading of pdf files (it will NEVER allow any browser specific pdf-reader to render/open your pdf files): var _window = window.open(fileURL, '_blank');
// To force downloading pdf uncomment following line of code and comment above line
// var _window = window.open(url, '', 'left=10000,screenX=10000')
_window.document.close();
_window.document.execCommand(
'SaveAs'
,
null
, url)
_window.close();
}
};
Download Files Using Javascripts
Different Types of Browser
AngularJS