Video Opens in new Tab
-
Hey there,
I just enabled the plugin and it’s working but not quite how I expected. If you click on the button to play the video, it opens the youtube page. I want it to just play there in an iframe after someone clicks the play button.
Can you please help me fix this issue? Thanks a lot.
The page I need help with: [log in to see the link]
-
Hi @aaron13223, I found the following code on your page that’s not standard:
(function(){var supportsPassive=eventListenerOptionsSupported();if(supportsPassive){var addEvent=EventTarget.prototype.addEventListener;overwriteAddEvent(addEvent);} function overwriteAddEvent(superMethod){var defaultOptions={passive:true,capture:false};EventTarget.prototype.addEventListener=function(type,listener,options){var usesListenerOptions=typeof options==='object';var useCapture=usesListenerOptions?options.capture:options;options=usesListenerOptions?options:{};options.passive=options.passive!==undefined?options.passive:defaultOptions.passive;options.capture=useCapture!==undefined?useCapture:defaultOptions.capture;superMethod.call(this,type,listener,options);};} function eventListenerOptionsSupported(){var supported=false;try{var opts=Object.defineProperty({},'passive',{get:function(){supported=true;}});window.addEventListener("test",null,opts);}catch(e){} return supported;}})();This code affects the
EventTargetprototype and forces “passive: true” if the useCapture flag isn’t set. I made a change to my plugin that I believe should fix the issue for you. Please make sure you’re using at least WordPress v5.6.0, then download plugin version 2.13.0 and let me know if the issue is fixed.-
This reply was modified 5 years, 3 months ago by
kevinweber.
-
This reply was modified 5 years, 3 months ago by
kevinweber.
-
This reply was modified 5 years, 3 months ago by
kevinweber.
Hey Kevin,
Thanks a lot for the quick turnaround. The code is indeed not standard. It’s to fix the pagespeed error “Does not use passive event listeners”
Thanks again for sending out a plugin update. I did upgrade the plugin and I’m using WP5.6 but it didn’t fix the issue, It’s still opening the YouTube page. I also disabled my caching plugin and cleared all the cache but that didn’t change anything.
In the end, I tried removing the passive event listener JS and it did fix the issue. I would be really glad if there’s way to still use that JS since pagespeed will start reporting the error again. Please suggest, thanks a lot.
@aaron13223 You can adjust your script to only set the passive flag if the passed in option doesn’t have the value true:
(function(){var supportsPassive=eventListenerOptionsSupported();if(supportsPassive){var addEvent=EventTarget.prototype.addEventListener;overwriteAddEvent(addEvent);} function overwriteAddEvent(superMethod){var defaultOptions={passive:true,capture:false};EventTarget.prototype.addEventListener=function(type,listener,options){if(options!==true){var usesListenerOptions=typeof options==='object';var useCapture=usesListenerOptions?options.capture:options;options=usesListenerOptions?options:{};options.passive=options.passive!==undefined?options.passive:defaultOptions.passive;options.capture=useCapture!==undefined?useCapture:defaultOptions.capture;}superMethod.call(this,type,listener,options);};} function eventListenerOptionsSupported(){var supported=false;try{var opts=Object.defineProperty({},'passive',{get:function(){supported=true;}});window.addEventListener("test",null,opts);}catch(e){} return supported;}})();This modified snippet as “if (options !== true) { … }” added within the addEventListener function call.
Hey Kevin,
Thank you so much for helping out. The JS and the YouTube video work perfectly. Thanks again and Happy New Yearβ¨
Great! Please consider leaving a quick rating here: https://ww.wp.xz.cn/support/plugin/lazy-load-for-videos/reviews/
Happy New Year π
Hey kevin
I have exact same issue, but could not figure out what is causing it:
https://www.cannabisanbauen.net/luftfeuchtigkeit/#luftfeuchtigkeit-und-temperatur@jrgong Your page is throwing a JS error in a portion of the code that’s not related to the video plugin: “Uncaught ReferenceError: wp is not defined”
You can check out the error using DevTools in the browser. It seems to be related to the “generate-offside-js-extra” script where it runs “wp.i18n.setLocaleData( localeData, domain );”. The script might not be added to the page properly.
Hey kevin
can you send a screenshot where you see that error? I can’t find anything in the console.
Hi @jrgong, the error message is gone. However, I found out what causes the link to open in a new window: An “onclick” attribute is being added to the video link that forces the link to open in a new tab. You must be using a plugin that causes this change, or your theme does this.
-
This reply was modified 4 years, 10 months ago by
kevinweber.
-
This reply was modified 4 years, 10 months ago by
kevinweber.
Hey @kevinweber
Thanks for taking a look. I realized this plugin is the culprit:
https://www.cannabisanbauen.net/wp-admin/options-general.php?page=external_links_in_new_windowsFortunately it allows to set a JS regex exception in its settings. We added this as exception:
https:\/\/www.youtube.comThx for your help, really appreciate it. Keep up the good work.
-
This reply was modified 4 years, 10 months ago by
jrgong.
-
This reply was modified 5 years, 3 months ago by
The topic ‘Video Opens in new Tab’ is closed to new replies.