Jquery 移动设备上的响应性或全尺寸
我有一个响应,我的客户想要一个选项,在手机上查看网站的全尺寸,一个选择退出响应选项。现在,在一位程序员同事的帮助下,我得到了:Jquery 移动设备上的响应性或全尺寸,jquery,Jquery,我有一个响应,我的客户想要一个选项,在手机上查看网站的全尺寸,一个选择退出响应选项。现在,在一位程序员同事的帮助下,我得到了: <script> var yetVisited = localStorage['visited']; if (!yetVisited) { // open popup localStorage['visited'] = "yes"; if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navi
<script>
var yetVisited = localStorage['visited'];
if (!yetVisited) {
// open popup
localStorage['visited'] = "yes";
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
var answer = confirm('Would you like to switch to the mobile version of Klofficerent');
if (answer) {
console.log('yes');
} else {
console.log('cancel');
viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'width=device-width, initial-scale=0, maximum-scale=1.0, user-scalable=0');
}
}
}
</script>
var yetVisited=localStorage['visted'];
如果(!yetVisited){
//打开弹出窗口
localStorage['visited']=“是”;
if(/Android | webOS | iPhone | iPad | iPod | BlackBerry/i.test(navigator.userAgent)){
var answer=confirm('您想切换到Klofficerent的移动版本吗');
若有(答复){
console.log('yes');
}否则{
console.log('cancel');
viewport=document.querySelector(“meta[name=viewport]”);
setAttribute(“内容”,“宽度=设备宽度,初始比例=0,最大比例=1.0,用户可伸缩性=0”);
}
}
}
这是一种工作方式,每当我访问链接时,我的网站就会在手机上响应,但当我点击其他页面时,它不会保存此设置,我需要它。有人有什么想法吗?您可以使用
(即#mobile
)向url添加一个参数,然后在加载任何页面时使用regex检查该参数。单击页面上的按钮时,可以将其添加到页面上的任何锚定href
属性中
单击按钮时,此代码会将“#mobile”添加到页面的URL中。加载页面时,如果URL以“#mobile”结尾,则代码将在所有
的href
属性中添加“#mobile”,您可以为我解释:(
if (window.location.href.indexOf("#mobile", window.location.href.length - "#mobile".length) !== -1) {
$("a").each(function(){
$(this)[0].href = $(this)[0].href.replace(/\#mobile$/, '') + "#mobile";
});
}
$("#mobile").click(function(){
window.location.href = window.location.href.replace(/\#mobile$/, '') + "#mobile";
location.reload();
});