Opening new window/tab without using `window.open` or `[removed].href`

后端 未结 3 1791
失恋的感觉
失恋的感觉 2020-12-11 10:09

I want to generate a link that is clicked right after creating, but nothing happens

Code:

var link = $("");
link.attr(&quo         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 11:10

    var link = $("");
    link.attr("href", "/dostuff.php");
    link.attr("target", "_blank");
    $("body").append(link);
    $("linky").live("click", function() {alert("hai"); $(this).remove()});
    $("linky").click();
    //$("linky").remove();
    

    So you actually react on the click event. And YES! The question is why would you want to do this?

提交回复
热议问题