The effect of different directional magnetic fields on critical temperature differences of oscillatory thermocapillary convection in a rectangular cavity with differentially heated side walls filled with two viscous, immiscible, incompressible fluids is simulated in the absence of gravity. In this two-layer fluid system, the upper layer fluid is the electrically non-conducting encapsulant boron oxide (BO), while the lower one is the electrically conducting molten indium phosphide (InP). The interface between the two fluids is assumed to be flat and non-deformable. The computational results show that all the magnetic fields along the , and directions can delay the transition from steady convection to oscillatory convection, and critical temperature differences increase with an increasing Hartmann number. Furthermore, the effect of a magnetic field along the direction is strongest, followed by that along the direction, and that along the direction is the weakest for the same intensity of the magnetic field.