我希望有一个链接,该链接在单击时会打开弹出窗口,但是如果用户未启用JS,我希望它能在新窗口中打开页面。

以下内容似乎无效,

<a id="tac-link" target="_blank" href="tac.html">terms and conditions</a>

function popUp(URL) {
day = new Date();
id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600,left = 445,top = 150');");
    }

$('tac-link').click(function() {
    popUp('tac.html');
    return false;
});

最佳答案

为了使此功能与浏览器更加兼容,您需要将事件对象传递给click处理程序,然后调用e.preventDefault();

例:

$( '#button' ).click( function( e ) {
    //... your code...

    e.preventDefault();
    return false;
} );

10-05 20:42
查看更多