Home / Admin / om.Action.close example 1
Duplicate Snippet

Embed Snippet on Your Site

om.Action.close example 1

Code Preview
js
// 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');
});

Comments

Add a Comment