2

次のコードは、ul li 内のすべてのリンクを検索し、それらの href 画像パスを取得してイベントを追加するため、ユーザーがリンクをクリックすると保存ダイアログが開きます。これは Internet Explorer でのみ機能します。他のブラウザでこれを行うにはどうすればよいですか。注:php、jsp、aspなどのサーバーを使用せずにこの機能が必要です。

$(document).ready(function () {
    $anchors = $("ul li a").each(function (i) {
        if($(this).attr('href').indexOf("jpg") > -1 || $(this).attr('href').indexOf("jpeg") > -1 || $(this).attr('href').indexOf("gif") > -1 || $(this).attr('href').indexOf("png") > -1){
            image_path = $(this).attr('href');
            if($.browser.msie){
                $(this).attr('href',"javascript:void(0);");
                $(this).click(function() { 
                    win = window.open(image_path,'win');
                    window.setTimeout('check();',1000);
                    return false; 
                });
            }
            else
            {
                // code for other browsers
            }
        }
    });
});

var win = null;
var image_path = null;
function check() {
    if (win.document.readyState=='complete'){
        win.document.execCommand("SaveAs");
        win.close();
    } else {
        window.setTimeout('check();',1000);
    }
}
4

0 に答える 0