You can use window.location
or window.location.href
which provides the current URL. In your example, you can use something like the following:
<a href="javascript:" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location);" target="_blank">
For more information see Window.location on Mozilla.org which has the following description:
The Window.location
read-only property returns a Location
object with information about the current location of the document.
Though Window.location is a read-only Location object, you can also assign a DOMString
to it. This means that you can work with location as if it were a string in most cases: location
= 'http://www.example.com
' is a synonym of location.href
= 'http://www.example.com
'.