When the contraction of maximal ideals is an injective open mapping Let $A$ and $B$ be two commutative rings with identity and let $f: A → B$ be a homomorphism of rings.
If $q$ is a prime ideal of $B$, $f^{-1}(q)$ is a prime ideal of $A$. Therefore we obtain a map
 $f' :  Spec(B) → Spec(A)$, where $f'(q) =f^{-1}(q)$.
Now is there any condition on $A$ or $B$ or $f$ such that 
 $f'(Max(B))\subseteq Max(A)$, $f'$ is injective and $f'$ is open mapping? (Spec(R) is the set of all prime ideals of $R$ and Max(R) is the set of all maximal ideals of $R$)

Let $k$ be an algebraically closed field and let $A$ and $B$ be finitely generated $k$-algebras. Let $f: A \to B$ be a homomorphism. I claim that if $\mathfrak{m} \subseteq B$ is a maximal ideal, then the pre image $\mathfrak{n}=f^{-1}(\mathfrak{m}) \subseteq A$ is a maximal ideal. 
To see this, consider the induced map $g: A/\mathfrak{n} \to B/\mathfrak{m}$. Since $\mathfrak{m}$ is a maximal ideal, $B/\mathfrak{m}$ is a finite extension of $k$. But $k$ is algebraically closed so $B/\mathfrak{m}=k$. Hence we have a sequence $k \to A \overset{g}\to k$. But $g$ is injective, so $A \cong k$, from which it follows that $\mathfrak{n}$ is maximal. 
In other words, $maxSpec$ constitutes a functor from the category of finitely generated $k$-algebras to the category of locally ringed spaces, provided $k$ is algebraically closed. 
If you want the map $f'$ to be injective, one sufficient condition is that $f:A \to B$ should be surjective. In this case, however, the map $f': maxSpec(B) \to maxSpec(A)$ is a closed embedding, so not open in general. 
An example of an open embedding is the map induced by a localization map $p: A \to A_f$. This gives a homeomorphism $p': maxSpec(A_f) \to maxSpec(A)$ onto the distinguished open $D(f)$. However, not all open sets in $maxSpec(A)$ are affine (though they locally are). As an example of when an open set fails to be affine consider the punctured plane $\mathbb{A}^2-\{0\}$.
It is actually quite difficult to find morphisms of (affine) schemes that are topologically open, in general. Usually, the best we can say is that the image of $f'$ is locally closed, i.e. a finite union of intersections of an open set with a closed set (see Chevalley's theorem). 
