我有一个网站(www.team2342.org),使用javascript自动重定向到移动网站(m.team2342.org)。我想给用户选择在手机上看到完整的网站。我通过在URL的末尾添加?skipmobile
来覆盖重定向来完成此操作。问题是,只要他们点击链接转到另一个页面,?skipmobile
就会被移除,并且他们会被重定向到移动网站。我已经编写代码,使用onclick
属性将?skipmobile
添加到href
链接的末尾;我只是无法将onclick属性应用于所有链接!这是我的...感谢您的帮助!添加?skipmobile标记到所有链接如果?url中的skipmobile
if (document.location.search.indexOf("skipmobile") >= 0) { document.getElementsByTagName("a").createAttribute("onclick","a = this; url = a.getAttributeNode('href').value; var smurl = url + '?skipmobile'; a.setAttribute('href', smurl);") } else if (screen.width < 699) { document.location = "http://m.team2342.org"; }
注:上面的代码是在<head>
在<script>
标签。
对不起,如果这是一个愚蠢的问题,但如何帮助? – user3842650