No, the network of sites itself is not infected. It appears you ran into a bad advertisement that was shown on a page you visited.
Stack Exchange currently uses the Google Ads platform to show ads on Stack Exchange sites. Ads are provided by third parties through the Google Display Network, (mostly?) outside the control of Stack Exchange. As such there can be bad adverts. Google does try to prevent this from happening, but can't always detect ads that try to bypass the restrictions in place.
You can report these ads to Google by clicking on the AdChoice icon found on adverts:
Clicking on that takes you to a page with more information about the advert, including a link to report bad adverts:
Malicious ads will do their utmost to make their 'app' look legitimate, trying to trick you into downloading it and installing (or accepting a browser extension, etc.). But, without your interaction, even adverts are not normally capable of installing additional software on your computer without your express permission (otherwise that'd be a very serious security issue with browsers, in general). Reporting the ad is the quickest way to have it removed from circulation.
Another option is to install an ad blocker, and not see adverts (good or bad) at all. Take into account that you need to weigh that choice against the fact that Stack Exchange tries to keep the lights on for these sites, in part, with money made from placing adverts. I'm neutral in that choice, I'm not advocating for or against using a blocker.