J
J
jussia2020-08-21 09:23:01
JavaScript
jussia, 2020-08-21 09:23:01

How to click on a button to open a page in a new tab in firefox?

It is necessary that after the successful completion of the request, a new tab is opened

<button type="button" id="planned" @click="acceptRoute(routeInfo.id)">Спланировать путешествие</button>

acceptRoute(id) {
      var apiUrl = '/routes/';
      return http.put(apiUrl + id + '/accept/').then((response) => {
        if (response.status == 200) {
          window.open(document.location.origin + '/plan/country/', '_blank')
        }

      })
    },


Here in this form
window.open(document.location.origin + '/plan/country/', '_blank')
called in firefox popup blocker. If you do it like this
acceptRoute(id) {
      var apiUrl = '/routes/';
      return http.put(apiUrl + id + '/accept/').then((response) => {
        if (response.status == 200) {
          document.querySelector('.planned').onclick = () => {
            window.open(document.location.origin + '/plan/country/', '_blank');
          }
        }

      })
    },


The opening of the tab occurs only after the second click

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
v3shin, 2020-08-21
@v3shin

There is a stupid option to do everything through the w ... form. But it all seems very strange.

function openUrlInTab(url) {
    let form = document.createElement('form');
    form.target = '_blank';
    form.action = url;
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question