window.open () does not load the page

2

I'm trying to open a link in a new window / tab but when it opens it does not load.

Controller:

public static Result loadCreateArtigo(){
     return ok(request().host()+request().path());
}

JavaScript:

$.SmartMessageBox({
  buttons : '[Não][Sim]'
}, 
function(ButtonPressed) {
  if (ButtonPressed === "Sim") {            
    Controller.loadCreateArtigo().ajax({
      success: function(data){
          window.open(data);
      },                   
  });
});

The 'data' variable returns me the url. What happens is that I open a new tab with the right url but the page does not load. if F5 the page loads right. I'm using Google Chrome. Any suggestions?

    
asked by anonymous 29.07.2015 / 11:36

1 answer

0

Hello,

As mentioned by our friend @ hugo-machado, it is necessary to include

'http:// ou https://'

in the URL, if applicable on the date.

To test, you can:

//verificar se existe http ou https
var data = 'http://asdasd' 
if(data.search(/https?\:\/\//ig) < 0){
    //caso não tenha, coloca pelo menos um http://
    data = 'http://'+data
    alert(data);
}

The search uses regex, as explained here

I hope to have helped

    
02.09.2015 / 23:27