0
我有一個jQuery模態UI基本上阻止用戶下載文件。我使用preventDefault
來停止下載管理器顯示。但是這會殺死GET
。如果使用preventDefault,我該如何繼續下載?
用戶點擊Agree
後,如何請求繼續下載?
我已經使用了這個,他們大多數都在做表單提交。
我有一個jQuery模態UI基本上阻止用戶下載文件。我使用preventDefault
來停止下載管理器顯示。但是這會殺死GET
。如果使用preventDefault,我該如何繼續下載?
用戶點擊Agree
後,如何請求繼續下載?
我已經使用了這個,他們大多數都在做表單提交。
記住文件的URL,然後將其設置爲window.location
,當用戶點擊Agree
時。
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
</head>
<body>
<a href="http://google.com" id="btn">Button</a>
<div id="dlg">Continue?</div>
</body>
</html>
的JavaScript:
var dlg$ = $('#dlg').dialog({
title: 'Confirm action',
autoOpen: false,
buttons: {
'Agree': function() {
dlg$.dialog('close');
window.location = dlg$.data('url');
}
}
}),
btn$ = $('#btn').on('click', function(e) {
e.preventDefault();
dlg$.data('url', this.href).dialog('open');
});
或者像window.location = $(this).target.href'一樣簡單,如果他感到困惑,那麼'this'就是''標籤。 – CppLearner
'了window.location =「UrlToFile''? –
代碼示例將幫助我們幫助您。 –