您的位置:首页技术文章
文章详情页

location.href = ’/m/’;//如何写当前页面url代码

浏览:80日期:2022-06-09 09:05:10

问题描述

<script type="text/javascript">

(function(){

var sUserAgent = navigator.userAgent;

if (sUserAgent.indexOf('Android') > -1 && sUserAgent.indexOf('Mobile') > -1 || sUserAgent.indexOf('iPhone') > -1 || sUserAgent.indexOf('iPod') > -1 || sUserAgent.indexOf('iPad') > -1 || sUserAgent.indexOf('Symbian') > -1 || sUserAgent.indexOf('IEMobile') > -1)

{

document.write(location.search);

location.href = '/m/';//如何写当前页面url代码

}

else

{

}

})();

</script>

问题解答

回答1:

//获取当前窗口的Urlvar url = window.location.href;//结果: 获取当前窗口的主机名var host = window.location.host;//结果:localhost:61768//获取当前窗口的端口var port = window.location.port;//结果:61768//获取当前窗口的路径var pathname = window.location.pathname;//结果:/Home/Index//获取当前文档的Urlvar URL = document.URL;//结果:http://localhost:61768/Home/Index?id=2&age=18//获取参数var search = window.location.search;//结果:?id=2&age=18

相关文章: