2017-01-06 9 views
0

私はjs通知を表示するwebappをテストしようとしています: new Notification("Title")それから私はそれをクリックすると特定の動作が発生するかどうかをテストする必要があります。どのように私はjavascriptで通知のユーザーのクリックをシミュレートできますか?JS通知のプログラムによるクリック

+1

可能な重複[JavaScriptでイベントをトリガするには?](http://stackoverflow.com/questions/2490825/how to-trigger-event-in-javascript) – Robba

答えて

0

ストア通知オブジェクトは、あなたがconstruction.Then後にあなたが何かを行うことができます取得

var notification = new Notification('test', { 
    icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', 
    body: 'this is body of the notification' 
    });         

    notification.onclick = function() { alert('got clicked'); } //handler 

    var event = new Event('click');  //event creation 
    notification.dispatchEvent(event);  //triggering 
関連する問題