我可以动态更改css,但我无法动态更改vewport(即通过单击“桌面版本”按钮的网站不会以完整大小显示)。单击桌面图标时,它会在iphone上打开桌面版但放大..
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
// Responsive Design Opt Out - cookie values
c_name = "optoutresponsive";
c_value = "1";
c_expires = 365;
// Responsive Design Opt Out - user actions
function optout() {
createCookie(c_name, c_value, c_expires);
location.reload();
}
function optin() {
eraseCookie(c_name);
location.reload();
}
$(document).ready(function () {
// Responsive Design Opt Out - helper functions
function optedout() {
if (readCookie(c_name) == c_value) {
return true;
}else {
return false;
};
}
function unlinkcss() {
jQuery('#mobilecss').remove();
}
function printstatus() {
$('#hv,#fullv').append(" ");
}
function renderuserselections() {
if (!optedout()) {
resp_html_selectors = "<div class='resp_selector_container'><input class='resp_selector' type='button' onClick='optout();' value='desktop version'/></div>"
}
else {
resp_html_selectors = "<div class='resp_selector_container'><input class='resp_selector' type='button' onClick='optin();' value='mobile version'/></div>"
}
$('#fullv').append(resp_html_selectors);
}
// Main
if (optedout()) {
unlinkcss();
printstatus();
}
renderuserselections();
});
</script>