This is my question i have an aspx page that has to show a popup message and when the user clicks ok begin download开发者_如何学编程 any help would be appreciated
Script
function download() {
if (confirm ('Download file?')) {
location.href = 'yourfile.pdf';
}
return false;
}
HTML
<a href='#' onclick='return download()'>Download</a>
You can use a click handler on your link or button:
<a href="url/to/file.txt" onclick="return confirm('are you sure you want to download this file?');">file text</a>
working example: http://jsfiddle.net/QRgvV/
In JavaScript you will have to create a modal which instructs the user to click on a link within the modal to continue the download. You can't use JS to force a download to begin, due to security concerns. So the best you can do is give them a message and a second link which will actually trigger the download (when the user manually clicks on it).
精彩评论