const link = document.createElement('a'); link.id = 'someLink'; //give it an ID! link.href = 'https://example.com'; // Your URL //Add the link somewhere, an appendChild statement will do. //Then run this document.getElementById('someLink').click();