During most of the 19th century the British were hostile to other country seizing Morocco and thus placing forces too close to Gibraltar (or in Spain's side, on both sides of it). During the war of 1859 they intervened to ensure that Spain would not demand territory for example.
Later, France (who had had an interest in the Moroccan atlantic ports since shortly after the conquest of Algeria) tried to get Spain to agree to a partition of Morocco in order to circunvent Britain's opposition, especially coinciding with the Margallo War of 1893. However, Spain at the time was dominated by PM Cánovas del Castillo who was opposed to militarism and colonialism, and instead preferred an independent unified Morocco under Spain's influence.