It is critical to take safety action if carcinogenic heavy metals and ammonia can be detected quickly, cheaply, and selectively in an environmental sample. As a result, compound 4a [4-(1-(2-(2,4-Dinitrophenyl)hydrazineylidene)-3-(naphthalen-2-yl)allyl)-5-methyl-1-phenyl-1 H-1,2,3-triazole] and compound 4b [4-(1-(2-(2,4-Dinitrophenyl)hydrazineylidene)-3-(naphthalen-2-yl)allyl)-1-(4-fluorophenyl)-5-methyl-1 H-1,2,3-triazole] were prepared. The aldol condensation process of 4-acetyl-1,2,3-triazoles 1a,b (Ar = C6H4; 4-FC6H4) with 2-naphthaldehyde yields 1-acetyl-1,2,3-triazoles 1a,b (Ar = C6H4; 4-FC6H4) (5-methyl-1-aryl-1 H-1,2,3-triazol-4-yl) -3-(naphthalen-2-yl)prop-2-en-1-ones 3a,b with a yield of around 95%. The target compounds 4a,b are obtained in around 88% yield by condensation of 3a,b with (2,4-dinitrophenyl)hydrazine in a refluxing acidic medium. Compounds 4a,b exhibited possible colorimetric detection for chromium ion in the range of 0–14 ppm and ammonia in the range of 0–20 ppm. As a result, this research suggests that strong electron-withdraw groups in related probes can improve anion detection ability, while the conjugation effect should also be considered while building structures.