Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Download Files Using Javascripts for Different Types of Browser
WhatsApp
Bipin Patil
Jan 15
2016
1.2
k
0
1
$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
Up Next
Download Files Using Javascripts for Different Types of Browser