Title: Video Opens in new Tab
Last modified: December 30, 2020

---

# Video Opens in new Tab

 *  Resolved [aaron13223](https://wordpress.org/support/users/aaron13223/)
 * (@aaron13223)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fvideo-opens-in-new-tab%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [kevinweber](https://wordpress.org/support/users/kevinweber/)
 * (@kevinweber)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-13849742)
 * Hi [@aaron13223](https://wordpress.org/support/users/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 `EventTarget` prototype 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](https://wordpress.org/support/users/kevinweber/).
    -  This reply was modified 5 years, 3 months ago by [kevinweber](https://wordpress.org/support/users/kevinweber/).
    -  This reply was modified 5 years, 3 months ago by [kevinweber](https://wordpress.org/support/users/kevinweber/).
 *  Thread Starter [aaron13223](https://wordpress.org/support/users/aaron13223/)
 * (@aaron13223)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-13850561)
 * 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.
 *  Plugin Author [kevinweber](https://wordpress.org/support/users/kevinweber/)
 * (@kevinweber)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-13852491)
 * [@aaron13223](https://wordpress.org/support/users/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.
 *  Thread Starter [aaron13223](https://wordpress.org/support/users/aaron13223/)
 * (@aaron13223)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-13853084)
 * Hey Kevin,
 * Thank you so much for helping out. The JS and the YouTube video work perfectly.
   Thanks again and Happy New Year✨
 *  Plugin Author [kevinweber](https://wordpress.org/support/users/kevinweber/)
 * (@kevinweber)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-13853110)
 * Great! Please consider leaving a quick rating here: [https://wordpress.org/support/plugin/lazy-load-for-videos/reviews/](https://wordpress.org/support/plugin/lazy-load-for-videos/reviews/)
 * Happy New Year 🙂
 *  [jrgong](https://wordpress.org/support/users/jrgong/)
 * (@jrgong)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-14541667)
 * Hey kevin
 * I have exact same issue, but could not figure out what is causing it:
    [https://www.cannabisanbauen.net/luftfeuchtigkeit/#luftfeuchtigkeit-und-temperatur](https://www.cannabisanbauen.net/luftfeuchtigkeit/#luftfeuchtigkeit-und-temperatur)
 *  Plugin Author [kevinweber](https://wordpress.org/support/users/kevinweber/)
 * (@kevinweber)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-14542241)
 * [@jrgong](https://wordpress.org/support/users/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.
 *  [jrgong](https://wordpress.org/support/users/jrgong/)
 * (@jrgong)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-14545555)
 * Hey kevin
 * can you send a screenshot where you see that error? I can’t find anything in 
   the console.
 *  Plugin Author [kevinweber](https://wordpress.org/support/users/kevinweber/)
 * (@kevinweber)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-14551329)
 * Hi [@jrgong](https://wordpress.org/support/users/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.
 * See: [https://ibb.co/DVfVZVs](https://ibb.co/DVfVZVs)
    -  This reply was modified 4 years, 10 months ago by [kevinweber](https://wordpress.org/support/users/kevinweber/).
    -  This reply was modified 4 years, 10 months ago by [kevinweber](https://wordpress.org/support/users/kevinweber/).
 *  [jrgong](https://wordpress.org/support/users/jrgong/)
 * (@jrgong)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-14553352)
 * Hey [@kevinweber](https://wordpress.org/support/users/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_windows](https://www.cannabisanbauen.net/wp-admin/options-general.php?page=external_links_in_new_windows)
 * Fortunately it allows to set a JS regex exception in its settings. We added this
   as exception:
    `https:\/\/www.youtube.com`
 * Thx for your help, really appreciate it. Keep up the good work.
    -  This reply was modified 4 years, 10 months ago by [jrgong](https://wordpress.org/support/users/jrgong/).

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Video Opens in new Tab’ is closed to new replies.

 * ![](https://ps.w.org/lazy-load-for-videos/assets/icon.svg?rev=3348904)
 * [Lazy Load for Videos](https://wordpress.org/plugins/lazy-load-for-videos/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/lazy-load-for-videos/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/lazy-load-for-videos/)
 * [Active Topics](https://wordpress.org/support/plugin/lazy-load-for-videos/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/lazy-load-for-videos/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/lazy-load-for-videos/reviews/)

## Tags

 * [new tab](https://wordpress.org/support/topic-tag/new-tab/)

 * 10 replies
 * 3 participants
 * Last reply from: [jrgong](https://wordpress.org/support/users/jrgong/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/video-opens-in-new-tab/#post-14553352)
 * Status: resolved