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. android - weex 項目createInstanceReferenceError: Vue is not defined2. PHPExcel表格導入數據庫怎么導入3. pdo 寫入到數據庫的內容為中文的時候寫入亂碼4. android - 哪位大神知道java后臺的api接口的對象傳到前端后輸入日期報錯,是什么情況?求大神指點5. javascript - 如圖,百度首頁,查看源代碼為什么什么都沒有?6. vue2.0+webpack 如何使用bootstrap?7. PHP類封裝的插入數據,總是插入不成功,返回false;8. mac連接阿里云docker集群,已經卡了2天了,求問?9. 微信渠道二維碼怎么使用?10. 我畢業以后在工作之余學了 PHP,都是自學 現在在找這方面的工作 求前輩指導學習方向 工作常用的知識
