I have the following question. It is well known that if we have a commutative ring $R$ and a multiplicative set $S\subset R$, then there exists a ring $S^{-1}R$ and a morphism $\pi:R\rightarrow S^{-1}R$ satisfying the following universal property: a morphism of commutative rings $f:R\rightarrow R'$ factorizes through $\pi$ if and only if $f(s)$ is an invertible element of $R'$ for each $s\in S$. My question is if this can be generalized to arbitrary $k$-algebras where $k$ denotes a commutative ring. More precisely, if we have a commutative $k$-algebra $R$ and a multiplicative set $S\subset R$, then $S^{-1}R$ is a $k$-álgebra, and the universal morphism $\pi$ is again a morphism of $k$-algebras. Is then true that any morphism of commutative $k$-algebras $g: R\rightarrow B$ factorizes through a morphism of $k$-álgebras $$S^{-1}R\rightarrow B$$ if and only if $g(s)$ is invertible in $B$ for each $s\in S\mkern1mu$? Thank you for your time.
EDIT : The same proof works in the case of $k$-algebras, because the morphism $\phi:S^{-1}R\rightarrow B$ is defined as $\phi(r/s):=s^{-1}f(m)$, so if $f$ is a morphism of $k$-álgebras then $\phi$ it is too.