Issues with Firefox persistently opening new windows can be caused by the websites you're visiting, an extension running on top of the browser or a malware infection that's taken root on your computer. Tweaking Firefox's internal settings and scanning your computer for possible security threats should be enough to prevent the problem from occurring again. Uninstalling and reinstalling the browser from scratch may also help resolve the issue, as this process resets Firefox and its configuration settings, and upgrades the software to the latest available version at the same time.
Launch Firefox and open the "Firefox" menu. Choose "Help" then "About Firefox" to check you are running the latest version of the software. If an update is available, it downloads automatically when the About Firefox dialog is opened -- select "Restart to Update" once the download has finished to apply the update.
Click or tap "Firefox" then choose "Options" and "Options" again to bring up the program's settings dialog. Open the "Content" tab and tick the box marked "Block pop-up windows." Click or tap "Exceptions" to manage a list of sites which are allowed to open up new windows. If you're experiencing problems with one or two sites in particular, make sure they aren't included on this list. Select "OK" to confirm the settings.
Click or tap "Firefox" then select "Add-ons" to see a list of all the add-ons and extensions installed on top of the Web browser. One of these extra tools could be generating new windows to advertise products or direct you to particular sites -- select "Disable" or "Remove" next to any of the extensions you're unsure of (click or tap the "More" link to see more details about an extension). Restart Firefox to apply your changes.
Update your anti-virus, anti-spyware and firewall software to the latest available versions and run a thorough system scan to look for malware software installed on your computer (check the help documentation included with each program for exact instructions). If problems are detected, remove the offending files and relaunch Firefox to see if the issue is resolved.
A malware infection is more likely to be the cause of your problems if the new windows appear at random and are advertising products completely unrelated to the sites you're currently browsing. If you aren't confident in the capabilities of your installed security software or you think they may have been compromised by a malware program, download and run an on-demand scanner from the Web -- two reliable and free options are Microsoft Safety Scanner and Spybot Search and Destroy.
If the problem persists try uninstalling Firefox completely from your system via the "Uninstall a program" link in Control Panel, then download and install the latest version from the official Mozilla website. This procedure should erase any unwanted add-ons or bugs within Firefox that may be causing the pop-up windows to appear.