How to add an automatic direct Google Drive link with JS

Hello everyone, welcome here, nowadays many website download links are direct and don't redirect to another website, direct download links make your website more professional. You may be using Google Drive for sharing your files with others on your website and you might be finding a solution for making it automatically direct download then this tutorial is for you, in this tutorial, I am going to show you How to add automatic direct Google Drive link in Blogger.
How it works?
It was made with javascript when it detects a link from drive.google.com it automatically converts it into a direct download link through this javascript.
How to add an automatic direct Google Drive link in the Blogger?
</body>
and paste the following JS just above it<script>/*<![CDATA[*/
var anchorDrive = document.querySelectorAll('a[href*="drive.google.com"]');
Array.prototype.forEach.call(anchorDrive, function(element, index) {
element.href = element.href.replace("/file/d/", "/uc?export=download&id=").replace("/view?usp=sharing", "").replace("/view?usp=share_link", "");
});
/*]]>*/</script>
How to add an automatic direct Google Drive link in a HTML Website?
</body>
and paste the following JS just above it<script>/*<![CDATA[*/
var anchorDrive = document.querySelectorAll('a[href*="drive.google.com"]');
Array.prototype.forEach.call(anchorDrive, function(element, index) {
element.href = element.href.replace("/file/d/", "/uc?export=download&id=").replace("/view?usp=sharing", "").replace("/view?usp=share_link", "");
});
/*]]>*/</script>
Conclusion
Hope this How to add an automatic direct Google Drive link with JS tutorial will be useful to you, if you have any doubts related to this tutorial ask me in the comment, and do share with your friends. Thanks for visiting, Have a nice day!
2 comments