首页 > 请问如何通过 javascript 判断 url 以打开不同大小的窗口?

请问如何通过 javascript 判断 url 以打开不同大小的窗口?

$('#playlist ul li > a').click(function(){
    if(href.indexOf("tudou.com") !== -1){
        window.open(this.href, "","top=100,left=355,width=640,height=500");
    }else{
        window.open(this.href, "","top=284,left=370,width=610,height=290");
    }
    return false;
});

这样写无法实现。。求助


$('#playlist ul li > a').click(function(){
if(document.URL.indexOf("tudou.com") !== -1){
    window.open(this.href, "","top=100,left=355,width=640,height=500");
}else{
    window.open(this.href, "","top=284,left=370,width=610,height=290");
}
return false;

});


我给个不同的答案,在@foomorrow的基础上改进的。

$('#playlist ul li > a').click(function(){
    var href = this.href;
    if(href.indexOf("tudou.com") !== -1){
        window.open(href, "","top=100,left=355,width=640,height=500");
    }else{
        window.open(href, "","top=284,left=370,width=610,height=290");
    }

    if (e && e.preventDefault) {
        e.preventDefault();  
    }else{  
        window.event.returnValue = false;
    }  
    return false;
});

$('#playlist ul li > a').click(function(){
    var href = this.href;
    if(href.indexOf("tudou.com") !== -1){
        window.open(href, "","top=100,left=355,width=640,height=500");
    }else{
        window.open(href, "","top=284,left=370,width=610,height=290");
    }
    return false;
});
【热门文章】
【热门文章】