I've got a button in my Meteor application that does the following:
user clicks button > event calls method > method calls external api using http > external api returns single sign on link > method returns link > event opens new window (tab) with link as url
My problem is that the new tab is being blocked by a popup blocker even though it is based on user action
Here's the event code:
Template.welcome.events({
'click #accessLms': function(e) {
e.preventDefault();
var submitButton = $('#accessLms').button('loading');
Meteor.call('getLmsLink', function(error, portalLink) {
if(error) {
sAlert.error(error.message);
submitButton.button('reset');
} else if(portalLink) {
window.open(
portalLink,
'_blank'
);
submitButton.button('reset');
}
});
}
});
Here is the method:
Meteor.methods({
'getLmsLink': function () {
[set vars...]
try {
var response = HTTP.call( verb, wceaApiAddress + endPoint, {
headers: {
"Request-Time": timeStamp,
"Api-Key": key,
"Signature": hash
}
});
} catch(error) {
throw new Meteor.Error(501, 'There was a problem getting a link to the E-Learning Portal');
}
var result = JSON.parse(response.content);
var portalLink = result.records.accessLink;
return portalLink;
}
});
Basic approach:
/redirect/token/
Template.onCreated
event of the template used in that route, perform the method call and get the url and auth token to the 3rd party site.location = newSiteHref
in that same code (in the new window) and redirect the user