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//獲取參數(shù)var search = window.location.search;//結果:?id=2&age=18
相關文章:
1. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個是怎么回事????2. 在應用配置文件 app.php 中找不到’route_check_cache’配置項3. html按鍵開關如何提交我想需要的值到數(shù)據(jù)庫4. mysql取模分表與分表5. gvim - 誰有vim里CSS的Indent文件, 能縮進@media里面的6. HTML 5輸入框只能輸入漢字、字母、數(shù)字、標點符號?正則如何寫?7. 跟著課件一模一樣的操作使用tp6,出現(xiàn)了錯誤8. PHP類屬性聲明?9. objective-c - ios 怎么實現(xiàn)微信聯(lián)系列表 最好是swift10. java - 安卓接入微信登錄,onCreate不會執(zhí)行
