0

I have the followwing two methods in an vuejs component:

    openLender: function(setUrl) {
        const win = window.open(setUrl, '_blank');
        win.focus();
    },
    getLender: function(setEnt, setEx, setRev, setCred, setDur, checkWishes, lender) {
        const vm = this;
        const request = 'lender_click';
        const setWishes = vm.arrayToString(checkWishes);
        axios({
            method:'get',
            url:'/api',
            params: {
                request: request,
                setent: setEnt,
                setex: setEx,
                setrev: setRev,
                setcred: setCred,
                setdur: setDur,
                setwishes: setWishes,
                setlender: lender
            },
            responseType:'json'
        })
        .then(function(response) {
            const url = response.data;
            vm.openLender(url[0].response);
        })
        .catch(function(error) {
            alert(error);
        });
    }

The problem is that i get this error:

TypeError: Cannot read property 'focus' of null

When I console.log(url[0].response) the response, it does show me the url that I got from the axios request, but when I use the openLender() method it gives me this error.

Any thoughts?

EDIT

I used @IgorDymov his solution in this post to work-around this problem

dexter
  • 155
  • 2
  • 15

1 Answers1

1

window.open method is always blocked by browser if it's not caused directly by a click event. Turn popup blocking off and it will work.

You may open the url in the same window or provide user a link to the new page though.

Igor
  • 809
  • 5
  • 16