Old CRT light guns worked by blanking the screen very briefly and then the gun detects bright light. Some worked by displaying bright regions sequentially. This happened quickly enough that the user wasn't aware.
CRTs fire a beam across the screen one line at a time starting from a corner, drawing horizontally (not unlike a typewriter filling a page). The old Nintendo method was to blank the screen when you pulled the trigger and then time how long it took for the gun to see the bright line being drawn.
Devices like the Wii, the xbone, etc now use two infrared light emitters separated by a fixed distance and the "light gun"/wiimote has an optical sensor that measures the point separation between these two sources. With the perceived separation, the known fixed distance, and some extra accelerometer data, the computer can triangulate the pointer position.
Note that a non-crt screen can still use the older blank screen method, just not the scanline timing method, but I expect that the Rambo game uses the infrared method.