-1

I am designing a static html/css website. In the contact page of the website, I have written an onclick function using inline js.

function goback() {
  alert("Thank you for contacting us ");
}
<button class="app-form-button" onclick="goback()">SEND</button>

I want to revert back to the home page once the person clicks on the popup on click function. But I don't have any idea on how to add an anchor tag to create a reference url to the home page within the script tag. Can anyone please help me?

Daweed
  • 1,419
  • 1
  • 9
  • 24
Sreelakshmi G
  • 39
  • 2
  • 9
  • did you mean to append as a child in your div element? or redirect to another page? – callmenikk Aug 28 '21 at 16:59
  • @callmenikk No I'm not using node interface here. I wanted to go back to the home page once I click ok on the onclick popup . – Sreelakshmi G Aug 28 '21 at 17:01
  • @SreelakshmiG I have added [answer](https://stackoverflow.com/a/68966540/13833218) below – Rifky Niyas Aug 28 '21 at 17:08
  • Does this answer your question? [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – kmoser Aug 30 '21 at 02:47

3 Answers3

2

Try the code below. According to this answer

Alert is a blocking function, means, if you don't close it, the code below will not execute. So you don't have to capture the alert close event, just write down the code below that alert, when alert window will be closed the code below will be executed automatically.

So, you can redirect the user to homepage after the alert statement via window.location.href

<button class="app-form-button" onclick="goback()">SEND</button>
<script>
  function goback() {
    alert("Thank you for contacting us ");
    window.location.href = "your homepage url";
  }
</script>
Spectric
  • 30,714
  • 6
  • 20
  • 43
Rifky Niyas
  • 1,737
  • 10
  • 25
1

You can use window object's propery location

after the alert, add this:

window.location.href="/index.html" /// or any other name of your homepage
Erfan
  • 1,725
  • 1
  • 4
  • 12
1

Use Location Replace It Won't Work here for some disabilities of stackoverflow

<button class="app-form-button" onclick="goback()">SEND</button>

<script>  
   function goback(){  
        alert("Thank you for contacting us "); 
        location.replace("https://www.google.com/")
        }
</script>  
callmenikk
  • 1,358
  • 2
  • 9
  • 24