We study theoretically the propagation of Josephson plasma waves (JPWs) localized on a slab of layered superconductor in the presence of an external dc magnetic field. The slab is sandwiched between two dielectric half-spaces and the wave modes propagate across the layers. We derive analytic expressions for the dispersion relations of the localized JPWs and present the numerical simulation for the effect of the external dc magnetic field on the dispersion. The anomalous dispersion of localized JPWs is predicted for a wide range of frequencies, wave vectors, and dc fields. Also, we discuss the possibility of the internal reflection of the localized modes in the inhomogeneous dc magnetic field. This phenomenon can find application in the terahertz electronics for the control of the localized mode propagation.