# Continuous functions sending a dense set to a dense set

Let $A\subseteq X$ is dense in $X$ and $B \subseteq Y$ is dense in $Y$, where X and Y are Hausdorff spaces. If a continuous function $f\colon X \rightarrow Y$ satisfies that its restriction to $A$ is a bijective map from $A$ to $B$. Then, does it imply that function $f$ itself is onto?

I have resolved this problem in the special case in which $X$ is assumed to be compact and I feel that it is a general result but not getting how to argue. And can we assume restriction map above is just onto?

-
How about $A=X=B=\mathbb Q$, $Y=\mathbb R$ and $f$ the identity? – Henning Makholm Nov 20 '11 at 17:33

I agree that this should hold when the domain is compact, since then $f(X)$ will be a compact subset of a Hausdorff space, and hence a closed set containing $B$.
But what if we take $X = (0, 1)$, $Y = [0, 1]$ with $A = B = (0, 1) \cap \mathbf{Q}$, and $f(x) = x$?