1

Apologies - I did search google but I'm not sure

How do I change the url of a button depending on which page it's currently on?

I have a sticky header with anchors on some pages I need something onClick that says

:if you're on "" page use this URL else use this URL

I have situations where it will reload the page instead of just scrolling to the anchor, but I need some cross site navigation.

Sorry this isn't explained very well Martyn

MaxiGui
  • 6,190
  • 4
  • 16
  • 33
  • if this is a different page, then the button will be different or if you use templates, you can still send to it a different url – MaxiGui May 06 '21 at 16:48
  • [What is the difference between Java and JavaScript?](https://stackoverflow.com/q/245062/10082297) – Henry Twist May 06 '21 at 16:54

1 Answers1

2

HTML

<button onClick="btnClick()">Click Me</button>

Javascript

<script>
function btnClick(){
 if(window.location.href == "yourdesireyrl"{
  window.location = "youurl to go";
 }else{
  window.location = "otherurl"
 }
}
</script>
Arashdeep Singh
  • 310
  • 3
  • 9