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. python - 數據與循環次數對應不上2. python - 如何對列表中的列表進行頻率統計?3. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙4. python小白 關于類里面的方法獲取變量失敗的問題5. django - Python error: [Errno 99] Cannot assign requested address6. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?7. python - Scrapy如何得到原始的start_url8. python小白,關于函數問題9. linux運維 - python遠程控制windows如何實現10. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?
