当我单击signin.xhtml上的 commandButton 时,我想运行一个 javascript 函数,但是当我单击它时,会重定向到dev.xhtml。我不想要这种重定向,我想留在signin.xhtml上。实际上它并不是真正的重定向,因为它是同一个index.xhtml页面,但具有延迟加载。
这是我来自signin.xhtml的 commandButton :
<h:form id="formSignInPartner" enctype="multipart/form-data">
<p:commandButton value="Géolocaliser mon commerce" onclick="getLocation()"/>
</h:form>
和index.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:pm="http://primefaces.org/mobile"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view renderKitId="PRIMEFACES_MOBILE" />
<h:head>
<script type="text/javascript" src="../javascript/geolocalisationPartner.js"></script>
</h:head>
<h:body>
<pm:page id="dev" lazy ="false">
<ui:include src="trash/dev.xhtml"/>
</pm:page>
<pm:page id="partnerSignIn" lazy="true">
<ui:include src="/Partner/signIn.xhtml"/>
</pm:page>
</h:body>
</html>
这里是脚本geolocalisationPartner.js但我不认为这是问题所在
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function error(msg) {
alert('Geolocalisation échouée :\n' + msg);
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, error, options);
} else {
alert('Votre navigateur\nne supporte pas\nla geolocalisation');
}
}
function showPosition(position) {
var long = position.coords.longitude;
var lat = position.coords.latitude;
$(PrimeFaces.escapeClientId('partnerSignIn:formSignInPartner:idlongitude')).val(long);
$(PrimeFaces.escapeClientId('partnerSignIn:formSignInPartner:idlatitude')).val(lat);
alert('Geolocalisation réussie !');
}