Neculai Andrei
Neculai Andrei

Reputation: 223

The new tab is blocked by pop-up blocker

I have the following code in JS:

$('#external-apply-job a').click(function(e) {
            var button = $(this);
            var url = $(this).data("system-url");

            loadPreloader();

            $.ajax({
                url: url,
                type: 'GET',
                async: false,
                data: {mode: 'json'},
                dataType: 'json',
            })
            .done(function(data) {

                if (data.type !== 'danger')
                { $(button).html(data.message); $(button).addClass('clicked'); $(button).trigger('click');} 
            })
            .always(function() {
                unloadPreloader();
            });
    });

And this is the link :

<a target="_blank" href="generated url"  title="some name">Sistem</a>

I know that using

$.ajax({
                    url: url,
                    type: 'GET',
                    async: false,
                    data: {mode: 'json'},
                    dataType: 'json',
                })

the click should be trusted event, but what is wrong is this code PS: If I use target="_self" all is ok but I need to open a new window. THX.

Upvotes: 1

Views: 150

Answers (2)

Neculai Andrei
Neculai Andrei

Reputation: 223

@Raphioly-San Thx for the sugest, I used async: true .

Upvotes: 0

JSchirrmacher
JSchirrmacher

Reputation: 3364

When the user clicks on your link, your ajax request should work as expected. The problem occurs after changing the link's code to the result of the ajax request and then programmatically call the the event handler via trigger(). An ajax request triggered by the program will not work due to security restrictions, at least if they open a new window / tab.

If you only want to open a new window or tab with an url, you could simply use window.open().

Upvotes: 1

Related Questions