簡體   English   中英

代碼無法在Safari中運行,但可以在所有其他瀏覽器中完美運行

[英]Code not working in Safari but perfectly working in all other browsers

我在Safari 8中遇到問題:

var a = document.createElement('a');
a.href = 'http://10.4.3.40:3000/sample_product_list';
a.download = 'sample_product_list';
document.body.appendChild(a);
a.click();

上面的代碼與Chrome和Firefox完美結合。 當我單擊一個按鈕時,以上代碼運行,一個文件被下載。 但是在Safari中,當我單擊該按鈕時,沒有任何反應。 Safari的控制台中未打印任何錯誤。 只是什么也沒有發生。 當我設置一個斷點,命中點並逐步瀏覽所有語句時,仍然沒有任何反應。 我在Safari中的代碼有什么問題?

在網址末尾添加/ 它會工作:

a.href = 'http://10.4.3.40:3000/sample_product_list/';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM