.submit(), some problem with safari, others works very well.
the requirement like this,
"download one file without refresh the page"
so, I dynamic created an iframe object contains a form with ’get' method and appended to 'body' through jQuery,
after that, I test ie, firefox, chrome etc, all works very well, but for Safari, only the first time it takes effect, the second time when you click trigger button, nothing happened, even an error message. attached is the testing code.
anyone can help me figure it out? thanks in advance.
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title></title>
- <script type="text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
- </head>
- <body>
- <script type="text/javascript">
- $(document).ready(function(){
- //document.write(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1);
- var downloadForm = "<form id='downloader' action='1.zip' method = 'get'><input type='submit' style='display:none'/></form>";
- $("<iframe />", {
- name: 'dlFrame',
- id: 'dlFrame',
- src:"about:blank"
- }).appendTo('body');
- setTimeout(function () {
- var doc = $("#dlFrame")[0].contentWindow.document;
- var $body = $('body', doc);
- $body.html($(downloadForm));
- }, 1);
-
- $("#test").click(function(){
- var $fxFrame = $("#dlFrame").contents();
- var $fx = $fxFrame.find('form');
- $fx.submit();
- });
- });
- </script>
- <button id='test' type="button">Download</button>
- </body>
- </html>