2014-07-15 36 views
0

我有一个网站(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>标签。

回答

0

您应该使用前缀而不是查询参数,并确保所有链接都是相对的。这样用户停留在前缀站点内。 例如www.site.com/重定向到手机和www.site.com/no-mobile/...转发到/ ...(?skipMobile)。

+0

对不起,如果这是一个愚蠢的问题,但如何帮助? – user3842650

相关问题