If you have some anti-virus software it will ordinarily doorstop stuff. However, be aware that some stuff can get through and for that I personally run malwarebytes every so often to keep the PC free from STD's. You can download the free trial version from here ==> Malwarebytes Anti-Malware - Protects You When Antivirus Can't - Protect Your PC Now and just delete it when done, or keep it hanging around, or even buy the high end version. My Bruv, who works at Microsoft, recommended it to me when my PC was totally gunged up with some malware and it worked a treat.
In which case you have probably inadvertently downloaded a malicious add-on to your browser. Happened to me about 5 years ago when a particular website downloaded the Babylon toolbar onto my browser. Took me hours to get rid of the damn thing.
These things work by hijacking your browser settings and re-directing you to sponsored websites (usually either clickbait junk or malicious depending on what you have been hijacked by). They will also re-set your browser automatically unless removed completely.
Here are typical instructions for removal of one particularly persistent one:
I had it this morning at about 11:00 but being on my phone (HTC One, Firefox) it was dim and therefore not legible. On pressing the back button, another dodgy page came up. A further press and the red page came back.
I tried the back button several times, only achieving the same two pages so had to close Firefox completely. It hasn't been back since but not using the site for several hours in the afternoon, I can't say whether it cleared of its own accord or was the result of intervention.