D
D
Dima2018-03-21 13:13:13
JavaScript
Dima, 2018-03-21 13:13:13

Perform an action if you are on a specific url?

if(location.href="мой url"){


       alert("y");     
      }else{
          alert("n");         
      };

always true. where am I wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2018-03-21
Dolgoter @DDolgy

In the first line... https://www.w3schools.com/js/js_comparisons.asp

J
JimmyTheWorm, 2018-03-21
@JimmyTheWorm

You missed == in the first line.
This would be more correct:

if(location.href==="мой url"){
      alert("y");     
      }else{
          alert("n");         
      };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question