qusqui21
qusqui21

Reputation: 169

JavaScript removes // from URL

enter image description here URL example = new URL(example.getExampleUrl()); exampleString += "example";

And I have problem with the url that removes // from link. So if I have http://www.google.pl, I get http: www.google.pl instead. I tried with a string, but then I have the same problem. Could anyone tell me how to make this string or url look like a regular link?

its look fine at java http://www.google.pl but at page it is without // so its look http: www.google.pl calendar etc

String test = "http://www.google.pl";
<a href="#" onclick="MyWindow=window.open(" 'http:="" www.google.pl','mywindow','width="600,height=600'');">test</a>

Answer to this is that there was a problem with " ' in java, i had to use it like that

onClick='MyWindow=window.open("+ example +")'

String example= "\"" + google.getUrl()+ "\",\""+google.getNameDisplay()+"\",\"width=600,height=600\"";

Upvotes: 1

Views: 72

Answers (1)

Robert Moskal
Robert Moskal

Reputation: 22553

The toString() method of URL should return just what you want. Try this snippet:

import java.net.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws MalformedURLException {
    URL example = new URL("http://mostmedia.com");
    System.out.println(example.toString());
    assert "http://mostmedia.com".equals(example.toString());

  }
} 

You can run it on repl.it: https://repl.it/CEVw/1

Upvotes: 1

Related Questions