location.href = ’/m/’;//如何寫當前頁面url代碼
問題描述
<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
相關文章:
1. javascript - 怎么看網站用了什么技術框架?2. php md5 16字符二進制格式 用JAVA寫3. javascript - vue 怎么渲染自定義組件4. mysql - 記得以前在哪里看過一個估算時間的網站5. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應6. 學習這個是不是要先學下css?7. javascript - 單個頁面執行多個jsonp的ajax請求,如何判斷一個ajax請求執行完畢執行再另一個?8. javascript - [MUI 子webview定位]9. javascript - angular最基礎的表單驗證10. javascript - node服務端渲染的困惑
