0

So I have a google site that I use for html hosting and I want to make a button that replaces the current window with a search window. So I do the normal routine:

<button onclick="doThis();">&#128270;</button>
<script>
function doThis(){
  window.location="https://sites.google.com/example/search";
}
</script>

It replaces the window but just says "sites.google.com refused to connect". Anyone know what's going on?

  • 2
    You haven't paid the bill? Actually, I'm getting a 404 Not found error. – Teemu Dec 08 '20 at 18:49
  • Is this within some kind of `iframe`? – imvain2 Dec 08 '20 at 18:51
  • 1
    Try `window.parent.location` instead if it's within an iframe. – imvain2 Dec 08 '20 at 18:52
  • Try `location.href` instead of just `location` and supply a ***valid*** URL. – Scott Marcus Dec 08 '20 at 18:54
  • AFAIK a server doesn't know that a request is coming from an iframe. If some commenters are thinking about "X-Frame-Options directive set to “sameorigin/deny“ error, it doesn't prevent the page being loaded, only that a (modern) browser won't show the page. – Teemu Dec 08 '20 at 18:57
  • @Teemu, I tested it in snippets and as a fiddle and was able to duplicate the error. Which prompted me to think of security for the iframe. – imvain2 Dec 08 '20 at 18:59
  • @imvain2 On the fiddle, try to show the source code of the page, it's loaded and shown without pain. And if you'll check the body of the response in the Network tab, you'll find the source code as well. – Teemu Dec 08 '20 at 19:01
  • yea you havent paid your bill – Joe Dec 08 '20 at 19:02
  • @imvain2 It looks like I've slightly misunderstood the question. I thought "_sites.google.com refused to connect_" is an actual error message, but it's just the notification Chrome shows. Despite of the notification, the page is really loaded (similarly to Firefox). – Teemu Dec 08 '20 at 19:33
  • I should also clarify, there was no iframe. – Finnegan Manthe Dec 08 '20 at 21:21

1 Answers1

0

Try to use window.location.assign()

<script>
function doThis(){
  window.location.assign("https://sites.google.com/example/search");
}
</script>

And "https://sites.google.com/example/search" does not exist. If you want to go to the search page, use: "https://www.google.com/" If you want to use a goodle search engine for your website, you have to do something like this: Passing html form values to google search query

A. Piks
  • 1
  • 3
  • I should have clarified, I was going to code the search page myself. And example is a placeholder for the actual sitename. I also tried redirecting it to a different page on the site, and that still didn't work. I even tried to take it to other websites and I still got the error even when I wasnt in preview mode. I also have all the google drive services as normal. And window.location.href didn't work either. – Finnegan Manthe Dec 08 '20 at 21:14