0
<iframe id="iframe" src="//player.net/14965165444001/default_default/index.html?videoId=4784345556001" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>

<button>click</button>

On iframe src, when clicked the "button".. it have to add "?autoplay=true" with the present src value.

Like this I add 5 elements inside the slider.

halfer
  • 18,701
  • 13
  • 79
  • 158
TDG
  • 1,206
  • 1
  • 15
  • 37

2 Answers2

1

Set the src of the iframe using .attr method

updateQueryStringParameter function is referred from amateur

function updateQueryStringParameter(uri, key, value) {
  var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
  var separator = uri.indexOf('?') !== -1 ? "&" : "?";
  if (uri.match(re)) {
    return uri.replace(re, '$1' + key + "=" + value + '$2');
  } else {
    return uri + separator + key + "=" + value;
  }
}

$('#update').on('click', function() {
  var url = $('#iframe').attr('src');
  var Updatedurl = updateQueryStringParameter(url, 'autoplay', 'true');
  $('#iframe').attr('src', Updatedurl);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<iframe id="iframe" src="//player.net/14965165444001/default_default/index.html?videoId=4784345556001" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>

<button id='update'>click</button>
Community
  • 1
  • 1
Rayon
  • 34,175
  • 4
  • 40
  • 65
0
var iframe = $('#iframe');
var src = iframe.attr('src');
$('button').click(function() {
  if (src.indexOf('autoplay=true') !== -1) {
    iframe.attr('src', src + '&autoplay=true');
  }
});
Ringo
  • 4,086
  • 2
  • 26
  • 40