Created
July 12, 2018 17:30
-
-
Save brianaohern/42f3b228465681a17650a6a22ab0ee36 to your computer and use it in GitHub Desktop.
om.Action.close Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function SaveToDisk forces file download instead of viewing in browser | |
function SaveToDisk(fileURL, fileName) { | |
// for non-IE | |
if (!window.ActiveXObject) { | |
var save = document.createElement('a'); | |
save.href = fileURL; | |
save.target = '_blank'; | |
save.download = fileName || 'unknown'; | |
var event = document.createEvent('Event'); | |
event.initEvent('click', true, true); | |
save.dispatchEvent(event); | |
(window.URL || window.webkitURL).revokeObjectURL(save.href); | |
} | |
// for IE | |
else if ( !! window.ActiveXObject && document.execCommand) { | |
var _window = window.open(fileURL, '_blank'); | |
_window.document.close(); | |
_window.document.execCommand('SaveAs', true, fileName || fileURL) | |
_window.close(); | |
} | |
} | |
// Specify the OptinMonster Event that will close our optin | |
document.addEventListener('om.Optin.success', function(event) { | |
event.detail.Campaign.startClose() | |
}); | |
// Specify the OptinMonster Event that will trigger our file download | |
document.addEventListener('om.Action.close', function(event) { | |
// Update with the url and name of the file you want downloaded on optin submission | |
SaveToDisk('http://www.example.com/download-file.pdf', 'Download.pdf'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment