Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:49:27+00:00 2026-05-27T15:49:27+00:00

Trying to change/modify the source of any/all iframe on the page where the src

  • 0

Trying to change/modify the source of any/all iframe on the page where the src includes youtube.com, and get the video id from the src url.

Here’s what I have so far that’s not working.

$(document).ready(function(){
changeYoutube();
function changeYoutube()
{
    $('iframe').each(function() {

   var that = $(this);
   var href = that.attr('src');

   if(href.search('youtube.com') != -1) {      
      that.attr('href', href+'&autoplay=1');
   }

});
});

I also need to put the video id from the url into a var. Example url:
http://www.youtube.com/embed/hP9rBDYYFvw?fs=1&feature=oembed
Where “hP9rBDYYFvw” is the video id in that url.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:49:28+00:00Added an answer on May 27, 2026 at 3:49 pm

    This is the solution:

      <script type="text/javascript">
        function changeYoutube() {
            $('iframe').each(function () {
    
                var that = $(this);
                var href = that.attr('src');
    
                if (href.search('youtube.com') != -1) {
                    that.attr('src', href + '&autoplay=1');
    
                   // code to get id
    
                        var tmp = href.split("?");
                    var tmp2 = tmp[0].split("/"); 
                    var ID = tmp2[tmp2.length - 1];
                }
    
            });
        }
    
        $(document).ready(function () {
            changeYoutube();
        });
      </script>
    

    First You have set the href attribute but you must set src attribute of iframe. Second You must first define the function that You call after document ready, and in Your code you haven’t close the function. Best Regards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to modify some open source code to change how it filters
We're trying to modify out NANT build script to pull changes from our remote
I´m trying to change a spring jsp example to use freemarker. I changed all
I am trying to change HTML code within an IFrame (it's on the same
I am trying to modify the source code of Joomla module but I don't
Based on this answer Get the subdomain from a URL , I am trying
I am trying to change the default value of 2 columns from 'N' to
I'm trying to compile code from an open source project, and I'm running into
I am trying to change change the url of current aspx page to the
I'm trying change an input mask for textbox when the the check box has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.