Open URL in a new window using Javascript

I am 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 part of the url, but I cannot get the next part to work.

I am struggling with the syntax. I would like to indicate the size of the new window 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?

+62
javascript
Jan 03 '13 at 2:03
source share
2 answers

Use window.open() :

 <a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');"> Share Page </a> 

This will create a link called Share Page , which will open the current URL in a new window with a height of 570 and a width of 520.

+115
Jan 03 '13 at 2:28
source share

Just use the window.open() function? The third parameter allows you to specify the size of the window.

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); 
+32
Jan 03 '13 at 2:09
source share



All Articles