Answer:
You can stop your dog from doing this if you make sure he never does it as a puppy, or when he does it the first time you should catch him in the act right when he is doing it and with a loud voice but not screaming you should tell him NO, and take him inside, if he continues, then do this a few times, but never a few minutes after he has moved on to another subject, because then he might think that you are mad at him or her for that other reason, or maybe your dog is just bored, or likes doing it.