beforeunload
保存されていないデータが含まれている場合にメッセージを表示するフォームを含む Facelet ページがあります。そのために、次の JavaScript を使用しています。
$(window).on('beforeunload', function(){
var val = document.getElementById("saveFormId:newInputId").value;
var flagVal = (val=='true');
if(flagVal)
return 'Are you sure you want to leave?';
});
同じページに、ロケールを変更する別のフォームがあります。
<h:form id="localeForm">
<p:selectOneButton value="#{localeBean.selectedLocale}"
valueChangeListener="#{localeBean.countryLocaleCodeChanged}"
onchange="submit()" style="height:1px;margin-top:7px;"
styleClass="ui-language-button">
<f:selectItems value="#{localeBean.languages}" />
</p:selectOneButton>
</h:form>
ただし、これはbeforeunload
ハンドラーもトリガーします。beforeunload
ハンドラーで上記のフォームの送信を無視したいと思います。どうすればこれを達成できますか?