I've been unsuccessful in trying out the answers in related questions so any help would be much appreciated.
I have a modal which displays a form in an iframe - this is scrollable. The issue occurs on ios where the body scrolls underneath instead of the iframe. I need to prevent the body from scrolling and allow the iframe to scroll.
The suggested fix from dementic doesn't work properly as the body underneath the modal still scrolls unless you touch scroll the modal in exactly the right place but this is very temperamental.
Modal:
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content bmd-modalContent">
<div class="modal-body">
<div class="close-button">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="embed-responsive embed-responsive-16by9">
<iframe id="formIframe" class="embed-responsive-item" frameborder="0"></iframe>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
jQuery/js:
(function($) {
$.fn.bmdIframe = function( options ) {
var self = this;
var settings = $.extend({
classBtn: '.bmd-modalButton',
defaultH: 360
}, options );
$(settings.classBtn).on('click', function(e) {
var allowFullscreen = $(this).attr('data-bmdVideoFullscreen') || false;
var url = window.location.href;
var fieldId = "Form_Source_URL";
var trackingURL = $(this).attr("data-bmdSrc") + '?' + fieldId + '=' + url;
var dataVideo = {
'src': trackingURL,
'height': $(this).attr('data-bmdHeight') || settings.defaultH,
'width': $(this).attr('data-bmdWidth') || settings.defaultW
};
if ( allowFullscreen ) dataVideo.allowfullscreen = "";
$(self).find("iframe").attr(dataVideo);
});
this.on('hidden.bs.modal', function(){
$(this).find('iframe').html("").attr("src", "");
});
return this;
};
})(jQuery);
jQuery(document).ready(function(){
jQuery("#myModal").bmdIframe();
});
//attempted fix to stop body scrolling
var iframe = document.getElementById('formIframe');
iframe.addEventListener('touchmove', function(e) {
e.preventDefault();
}, false);