Let $f:A\rightarrow B$ be a homomorphism of integral domains. Is it possible to extend $f$ to the integral closures of $A$ and $B$? I am working on question II.3.8 in Hartshorne's Algebraic Geometry. Our professor mentioned a very useful algebraic result for the problem but I cannot find a reference anywhere.

Let $f:A\rightarrow B$ be a ring morphism of integral domains, and let $\tilde{A}$ and $\tilde{B}$ be the respective integral closures. Then there exists a morphism $\tilde{f}:\tilde{A}\rightarrow \tilde{B}$.

I think the result is supposed to be "there exists a morphism $\tilde{f}:\tilde{A}\rightarrow \tilde{B}$ that extends $f$", but I'm not sure.
Any insight on why this is true or not or a reference for the result would be much appreciated.
My idea to construct such a morphism is as follows.
Let $r$ be an element in $\tilde{A}$. Then $r$ is the root of a polynomial $x^n+\cdots+a_1x+a_0$, with $a_i\in A$.
Then let $\tilde{f}(r)$ be the root of the polynomial $x^n+\cdots+f(a_1)x+f(a_0)$ in $\tilde{B}$. I'm not sure if this is indeed a homomorphism however.
 A: The result is false in general, as demonstrated by user26857's counterexample.
However here is an elementary proof  if $f$ is injective.
This special case where $f$ is injective suffices for solving Hartshorne's Exercise II.3.8, which  motivated the OP's question.  
Let $K=\operatorname {Frac}(A)$ be the fraction field of $A$ and $L$ be the fraction field $L=\operatorname {Frac}(B)$ of $B$.
The ring morphism $f:A\to B$  has a unique extension to a field morphism $F:K\to L$.
Any element $k\in \tilde{A}$ has an image $F(k)\in L$ which is (by the OP's reasoning) integral over $F(A)=f(A)$ and thus a fortiori integral over $B$ (since $f(A)\subset B$).
Thus $F(k)$ belongs to $\tilde B $ and we have proved that $f$ has a unique extension to $$\tilde f=F\vert\tilde A:\tilde A \to \tilde B .$$
A: 
Let $f:A\rightarrow B$ be a homomorphism of integral domains. Is it possible to extend $f$ to the integral closures of $A$ and $B$?

No, it's not!
Let $A=\mathbb Z[\sqrt{-3}]$, $B=\mathbb Z[\sqrt{-3}]/(2,1+\sqrt{-3})$, and $f:A\to B$ be the canonical projection.
Then $B\simeq\mathbb Z/2\mathbb Z$, $\tilde A=\mathbb Z[\frac{1+\sqrt{-3}}{2}]$, and $\tilde B=B$.
Set $x=\frac{1+\sqrt{-3}}{2}$. We have $x^2-x+1=0$.
Suppose $\tilde f:\tilde A\to\tilde B$ is a ring homomorphism. Then $\tilde f(x)\in\mathbb Z/2\mathbb Z$. On the other side, $\tilde f(x^2-x+1)=0$ hence $\tilde f(x)^2-\tilde f(x)+1=0$, a contradiction.
A: Consider the set of ring homomorphisms $\hat f\colon \hat A\to \tilde B$ where $A\subseteq \hat A\subseteq \tilde A$ and $\hat f|_A=f$. The conditions of Zorn's lemma are verified, hence there exists a maximal such homomorphisms $\hat f\colon \hat A\to \tilde B$. Suppose $a\notin \hat A$. Then pick an irreducible monic polynomial $p\in A[X]$ with $p(a)=0$ and pick $b\in\tilde B$ with $f(p)(b)=0$. Then we can extend $\hat f$ to $\hat A[a]$ by declaring $f(\sum c_ia^i)=\sum \hat f(c_i)b^i$, which is well-defined by the choice of $b$ (or: we clearly have an induced homomorphism $\hat A[X]\to \tilde B$ that sends $a\mapsto b$; this factors over $A[X]/(p(X))\cong \hat A[a]$). By maximality of $\hat A$, we conclude $a\in \hat A$, so $\hat A=\tilde A$.
