-1

I have the following code set up to open a URL in a the same Window but requires two clicks to open, any idea's why?

            $('button.more-details-link').on("click",function(){
                window.open(url, '_self')
            });
Pianoc
  • 763
  • 1
  • 11
  • 32
  • Did you mean to open the up the URL in the _same_ window? If not, then you want your target to be `_blank` instead of `_self`. – patstuart Sep 09 '15 at 14:38

2 Answers2

4

Try wrapping it in a document ready function: https://jsfiddle.net/z2b08x7t/

$(function(){ 
$('button.more-details-link').on("click",function(e){
     e.preventDefault();
     var url = "google.com"
                window.open(url, '_self')
            });
    });

Or if you want to open it in a blank window:

 $(function(){ 
    $('button.more-details-link').on("click",function(e){
         e.preventDefault();
         var url = "google.com"
                    window.open(url, '_blank')
                });
        });
Mark
  • 4,773
  • 8
  • 53
  • 91
0
$(function() {
$('button.more-details-link').on('click', function(){
  window.open('url', 'window name', 'window settings');
  return false;
});
});

or you can use

$(function(){
  $('yourselector').prop('target', '_blank');
}); 

For details regarding window.open() you can check this article

Varun
  • 597
  • 7
  • 26