JSGarcia JSGarcia - 7 months ago 22
Javascript Question

Check if a link has been opened in another window [JS or jQuery]

I have a simple jQuery script that launches modal to report the page is loading (working properly) because there are times when script processing takes some time.

My problem comes when the user clicks on the link that launches a modal in new window (either with the middle mouse button or via the contextual menu).

Then, the modal displays and the page loads in a new tab but in the parent the modal is visible (when it should not because the content is already loaded in another tab).

Is it possible to launch the modal only when the request is made for the same tab, not a new one?

Here is the jQuery code and a demo:

// Loading Modal
$(' #launch ').click(function(){
$('#loadingModal').modal('show');
});


https://jsfiddle.net/e914a1jv/

Thank you very much to all.

Solution:

Here is the resulting jQuery code:

// Loading Modal
$(' #launch ').mousedown(function(evt) {
if(evt.which == 1)
{
if ( evt.ctrlKey === false )
{
$('#loadingModal').modal('show');
}
}
});

Answer

SOLUTION

Here is the resulting jQuery code:

// Loading Modal
$(' #launch ').mousedown(function(evt) {
    if(evt.which == 1) 
    {
        if ( evt.ctrlKey === false )
        {
            $('#loadingModal').modal('show');
        }
    }
});