我有一個表單,並且我希望在提交值之前用戶關閉頁面時要求確認。我已經嘗試了this question中描述的腳本,但它似乎不起作用:userSubmitted的值總是如此,並且彈出窗口沒有出現。以未提交的形式關閉頁面時要求確認
模板中的代碼是:
<script>
window.onbeforeunload = function() {
if(!userSubmitted)
return 'Are you sure that you want to leave this page?';};
</script>
在我的控制器代碼:
$userSubmitted=false;
//...
$form->handleRequest($request);
if ($form->isValid()) {
$userSubmitted=true;
//...
return $this->render('DefaultBundle::formupload.html.twig', array(
'form' => $form->createView(), 'userSubmitted->$userSubmitted
));
//...
像'onbeforeunload =函數(){返回提示(「你確定?「); }' –
onbeforeunload的作品,如果你不把你的代碼,我們不能幫你 – giammin
您可能正在尋找: http://stackoverflow.com/questions/16606496/show-message-box-ext-window-beforeclose-事件 –