Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
Expand|Select|Wrap|Line Numbers
- let clickEvent = new Event('click', {
- bubbles: true,
- cancelable: true,
- view: window
- });
Added a style to all clickable elements:
Expand|Select|Wrap|Line Numbers
- cursor: pointer;
Expand|Select|Wrap|Line Numbers
- const whatDevice2 = /iPad|iPhone|iPod/.test(navigator.userAgent);
- let whatEventUse2 = whatDevice2 ? 'touchstart' : 'click';
This works on all platforms and browsers except Safari\IOS.
Here is all the code:
Expand|Select|Wrap|Line Numbers
- const whatDevice2 = /iPad|iPhone|iPod/.test(navigator.userAgent);
- let whatEventUse2 = whatDevice2 ? 'touchstart' : 'click';
- let play = document.querySelector('#app-2 .cp-play-icon.cp-play-icon-paused');
- let originalId = audioPlay2[index].dataset.originalId;
- let elementToClick = document.querySelector(#${originalId});
- let audioButton = popupElement2.querySelector('a.popup__description_audio');
- audioButton.addEventListener(whatEventUse2, () => {
- if (elementToClick.classList.contains('cp-playlist-link_current')) {
- play.click();
- setTimeout(addIdLi2, 0);
- } else {
- elementToClick.click();
- { setTimeout(addIdLi2, 0);
- }
- });
If anyone has any knowledge in this matter, please give me advice on what to do or point me in the right direction).
I would be glad to have any information, thank you!