Added device detection and event handler JavaScript.