Check out my HTML code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<div id="myModal" class="modal fade" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p class="modal-title">SECRETS OF SUPERIOR CUSTOMER SERVICE (July 22, 2016)</p>
</div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="http://chishare.cc/embed/2107778410/" allowfullscreen="" width="640" height="360" frameborder="0"></iframe>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
My main question is: How to change this iframe src video without page refresh?
Like this:
<button type="button" onclick="src1()">Change to video 1</button>
<button type="button" onclick="src2()">Change to video 2</button>
<button type="button" onclick="src3()">Change to video 3</button>
<button type="button" onclick="src4()">Change to video 4</button>
And their respective functions:
function src1(){
-- Change the iframe src link of myModal
}
function src2(){
-- Change the iframe src link of myModal
}
...
Can you help me?
Thanks
2
Answers
Step 1: Use an ID for the iframe…
Step 2: Update your buttons…
Step 3: Include this function…
I would suggest using 1 function instead of 4, and add your links as data inside of each button. You could also add those links dynamically at runtime. I used a placeholder video from youtube on a demo for button 1, and as you see you can switch out your iframe src using the following jQuery function.