Issue with window.replace() method having search params in URL

Viewed 46

I m trying to open a new window from my web page while clicking on the 'number#' lsted in my page, actually, it's a google search(eg: https://www.google.com/search?q=12312), and got the results in the new tab

I am also trying to replace the search query parameter again while clicking on another Number#(eg: https://www.google.com/search?q=456456), But replace functionality not working. Below I am placed the demo code

let win;
let firstSearch = () => {
    win = window.open('https://www.google.com/search?q=123123', '_blank');
}

let secondSearch = () => {
    win.location.replace('https://www.google.com/search?q=345345')
}

But its not working. But I remove '/search' from the URL replacement is happen. So, any solution for this search and replacement parameters

Codepen

1 Answers

That is not working because the site tells the browser that they don't want to be loaded in X-Frame. That's why your code works using Bing but not Google...

from: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe>, <embed> or <object>. Sites can use this to avoid click-jacking attacks, by ensuring that their content is not embedded into other sites.

Related