문제

I'm trying to launch the steam client using their web protocol: https://developer.valvesoftware.com/wiki/Talk:Steam_browser_protocol

I'm using jQuery. Here is a example:

$(function() {
    // a bunch of stuff happens
    $("#content").append('<a id="launcher" href="steam://connect/' + server.ip + ':' +     server.port + '"></a>');
    $("#launcher").click();
});

Now I know this won't work... event delegation? But essentially it's what I want to do. Any ideas?

도움이 되었습니까?

해결책

You should call the native DOM's click directly

$("#launcher")[0].click();

OR

You can use .get(), it retrieves the DOM elements matched by the jQuery object and call native DOM's click directly.

$("#launcher").get(0).click();

다른 팁

Try

$(document).on("click", "#launcher", function () {
    // code
});

Try to use .trigger():

$("#launcher").trigger('click');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top