-2
let url ='https://www.google.com/search?q='+document.getElementById('search').value;
             window.open(url)

This works fine but I want to open this in the same tab

so when I use
window.open(url,"_self") or

``` window.location.href =url; ````

it just reloads the same page

1 Answers1

0

You want to use this:

window.location.assign(url);

For more information: https://developer.mozilla.org/en-US/docs/Web/API/Location/assign

Mähnenwolf
  • 720
  • 10
  • 30
  • Which has the same effect as `window.location.href` which, according to OP, does _"just reloads the same page"_ – Andreas Oct 10 '22 at 07:59
  • While it doesn't make sense it doesn't seem to work with `.href`, but using `.assign` is better, as it is a method unlike `.href`, imo. – Mähnenwolf Oct 10 '22 at 08:01
  • It doesn't make sense because the question lacks a bunch of information. And without those information (a.k.a. [mcve]) that problem doesn't exist -> OP does something else that "breaks" that function – Andreas Oct 10 '22 at 08:15