Popup block when opening url from Outlook Webaddin

I am trying to open a url when a user clicks a button in a plugin view. But the web addin is throwing an error.

My code for opening url:

let a = document.createElement("a");
a.setAttribute('target', '_blank');
a.setAttribute("style", "display: none");
document.body.appendChild(a);
a.href = finalUrl;
a.click();
document.body.removeChild(a);

      

Error message:

enter image description here

The app is rejected from the store because of this error. How can I overcome this error?

I don't want to use the Dialogue API that doesn't open the url in the browser.

+1


source to share


1 answer


As a general rule, a window will always be blocked from opening unless it is a direct result of a user action . For more information see this SO question: Avoid browser popup blockers .

You are launching a popup because you are trying to emulate click()

. Since this is not a direct user action, this action will be flagged by all major browsers.



You will need to present the user with a clickable element (link, button, etc.) that will open a new window.

+1


source







All Articles