Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Open window in new tab after async api call

I have this function I want to call followed by the opening of a page in a new tab after a user clicks an element in my VueJS application similar to this:

const someFunction = async () => {
   const value = await api.someCallToApi();
   window.open('https://example.com', '_blank').focus();
}

I am not allowed to do this, probably due to the await resulting in the window.open not being a direct result of a user action(?)! Due to the way my application is setup the order of the api call and opening of the window in the new tab is relevant.

What would be a solid and modern way of tackling such an issue?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In an ideal world, all asynchronous functions would already return promises. But there may be still old libraries that use await. You can create a Promise that wraps the await function as below:

const delay = (ms) => new Promise(resolve => setTimeout(resolve.bind(null, ms/1000), ms));


delay(3*1000).then((sec) => alert(sec + " seconds passed"));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!