window.onload = function() { const search_engine = "https://www.startpage.com/do/asearch?q="; const domain = "oskog97.com"; // Add a site: operator here if you want. var this_page = location.href.replace(location.origin,''); var search_query = domain + this_page.replace(/[^A-Za-z0-9]/g, "+"); // There is always a leading slash in this_page. No need to add anything. var iframe = document.querySelector("iframe#autosearch"); iframe.setAttribute("src", search_engine + search_query); };