Copy current item ID to clipboard using SharePoint custom action

Recently I had a requirement where the user needed to copy an item’s URL to clipboard in SharePoint.

Using the SharePoint designer, I created a Custom Action and in the “Navigate to URL” action type I set the following.

javascript:clipboardData.setData("Text", window.location.protocol+'//'+window.location.hostname+':'+window.location.port +'/sites//Lists//DispForm.aspx?ID='+'{ItemId}');alert('Item URL \"'+window.location.protocol+'//'+window.location.hostname+':'+window.location.port +'/sites//Lists//DispForm.aspx?ID='+'{ItemId}'+'\" copied to clipboard');