[javascript] Open URL in new window with JavaScript

I'm making a "share button" to share the current page. I would like to take the current page URL and open it in a new window. I have the current URL part working, but can't seem to get the next part working.

I'm struggling with the syntax. I would like to specify the new window size to width=520, height=570.

Something like:

<a target="_blank"
   href="https://www.linkedin.com/cws/share?mini=true&amp;url=[sub]" 
   onclick="this.href = this.href.replace('[sub]',window.location)">
    LinkedIn
</a>

Any ideas?

This question is related to javascript new-window

The answer is


Just use window.open() function? The third parameter lets you specify window size.

Example

var strWindowFeatures = "location=yes,height=570,width=520,scrollbars=yes,status=yes";
var URL = "https://www.linkedin.com/cws/share?mini=true&amp;url=" + location.href;
var win = window.open(URL, "_blank", strWindowFeatures);

Don't confuse, if you won't give any strWindowFeatures then it will open in a new tab.

window.open('https://play.google.com/store/apps/details?id=com.drishya');