skip to Main Content

Page sometime contain single embedded iframe video. I wish top open those specific videos in the current tab.

<iframe allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" marginheight="0" marginwidth="0" scrolling="no" frameborder="0" width="100%" src="https://streamview.com/v/wkx5ntgwdv5b"></iframe>

My code:

(function() {
    'use strict';

    var openontaB = document.querySelector('iframe').src;
    window.location.href = openontaB;
})();

The issue is that the above code does not open the correct iframe src. How would I make it work/match only for an iframe that contains the string streamview.com?

​Thanks

2

Answers


  1. Try (untested):

    (function() {
        'use strict';
    
        const allIF = document.querySelectorAll('iframe');
    
        allIF.forEach( frm => {
            const openontaB = frm.src;
            if (openontaB.includes('streamview.com')){
                window.location.href = openontaB;
            }
        });
    })();
    
    Login or Signup to reply.
  2. You can also do something like this:

    // look for an iframe with 'streamview.com' in its src
    const iframe = document.querySelector('iframe[src*="streamview.com"]');
    // if found, set location
    iframe && (location.href = iframe.src);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search