JavaScript Mootools将文件类型设置为在新窗口中打开

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript Mootools将文件类型设置为在新窗口中打开相关的知识,希望对你有一定的参考价值。

/* classes */
var OpenLinks = new Class({
    //initialization
    initialize: function(file_extensions,override_targets,target,no_class) {
        
        //analyze all anchors
        $$('a').each(function(el) {
            
            //check each href for case-insensitive file extensions
            var str = el.get('href');
            var ext = str.substring(str.lastIndexOf('.') + 1,str.length)
            if(file_extensions.contains(ext.toLowerCase()) && ((override_targets || !el.get('target')) && !el.hasClass(no_class + '')))
            {
                el.setProperty('target',target ? target : '_blank');
                el.setStyle('color','#f00');
            }
        });
    }
});
		
/* do it! */
window.addEvent('domready', function() {
//enter in as lower case
var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],1,'_blank','no-target');/works
//var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],1,'_blank');//works
//var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],1);//works
//var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],0);//works
//var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png']);//works
});

以上是关于JavaScript Mootools将文件类型设置为在新窗口中打开的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript Mootools:Fx.Scroll将页面移动到顶部

Mootools 是不是 100% 防止 javascript 关闭?

Javascript mootools脚本添加

普通的 JavaScript 是不是比使用 jQuery 或 MooTools 等框架更好? [关闭]

MooTools CORS 请求与原生 Javascript

JavaScript Mootools可拖动/调整大小示例