A discharge from the eyes is typically a sign of some form of eye irritation or infection. For example, a stringy discharge associated with itching is common in children who suffer from allergies. These symptoms can be treated with allergy medications, including eye drops, and by reduced exposure to the allergen.
The presence of a thicker discharge associated with a red eye and without itching is often caused by an infection known as conjunctivitis. Both viruses and bacteria may cause conjunctivitis. Viral conjunctivitis is self-limiting and does not usually require specific treatment. Bacterial conjunctivitis, particularly when mild, is usually self-limiting as well, though treatment with antibiotic drops will often result in more rapid resolution.
Prevention involves common sense: Wash your hands often, and avoid direct contact with people who have an obvious infection.