Skip to content

Instantly share code, notes, and snippets.

@aaryan79831014
Created September 14, 2018 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaryan79831014/68bc62fadf428199269084a00d676f46 to your computer and use it in GitHub Desktop.
Save aaryan79831014/68bc62fadf428199269084a00d676f46 to your computer and use it in GitHub Desktop.
fitting iframe content to the screen in iOS (Make the iframe responsive in iOS)
I needed a cross-browser solution. Requirements were:
needed to work on both iOS and elsewhere
don't have access to the content in the iFrame
need it to scroll!
Building off what I learned from @Idra regarding scrolling="no" on iOS and this post about fitting iFrame content to the screen in iOS here's what I ended up with. Hope it helps someone =)
HTML
<div id="url-wrapper"></div>
CSS
html, body{
height: 100%;
}
#url-wrapper{
margin-top: 51px;
height: 100%;
}
#url-wrapper iframe{
height: 100%;
width: 100%;
}
#url-wrapper.ios{
overflow-y: auto;
-webkit-overflow-scrolling:touch !important;
height: 100%;
}
#url-wrapper.ios iframe{
height: 100%;
min-width: 100%;
width: 100px;
*width: 100%;
}
Javascript
function create_iframe(url){
var wrapper = jQuery('#url-wrapper');
if(navigator.userAgent.match(/(iPod|iPhone|iPad)/)){
wrapper.addClass('ios');
var scrolling = 'no';
}else{
var scrolling = 'yes';
}
jQuery('<iframe>', {
src: url,
id: 'url',
frameborder: 0,
scrolling: scrolling
}).appendTo(wrapper);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment