Business requirement trying to be met: Loading an existing page within an iframe, emulating an iphones user agent. The reason this needs to happen client side, is that there are client side scripts which detect the user agent and appends some classes onto the html element. Based on this the style of the site will radically change as the CSS targets elements based on the html classes.
So it would take and turn it into or in the case that I'm trying to resolve here etc.
Using window.open works (as demonstrated in this code) within chrome. The site renders with the proper mobile styling.
Using the iframe works, but only in FF.
Ideally, I'd like to have the iframe version working within Chrome and FF.
Any thoughts?
<script type="text/javascript">
navigator.__defineGetter__('userAgent', function () {
return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5';
});
var win = window.open('/home/get');
win.navigator.__defineGetter__('userAgent', function () {
return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5';
});
win.location.href = '/home/get'; //required
$(function () {
var frame = $('<iframe width="320" height="480"></iframe>');
frame.hide();
$('#container').append(frame);
(frame[0].contentWindow || frame[0].contentDocument).navigator.__defineGetter__('userAgent', function () {
return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5';
});
frame.attr('src', '/home/get');
});
frame.fadeIn();
});
</script>