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 - NavigationView 的側滑菜單中如何保存新增項(通過程序添加)2. mysql服務無法啟動1067錯誤,誰知道正確的解決方法?3. php - 第三方支付平臺在很短時間內多次異步通知,訂單多次確認收款4. php7.3.4中怎么開啟pdo驅動5. tp5 不同控制器中的變量調用問題6. 這段代碼既不提示錯誤也看不到結果,請老師明示錯在哪里,謝謝!7. jquery清除input type為password?8. 老師 我是一個沒有學過php語言的準畢業生 我希望您能幫我一下9. ueditor上傳服務器提示后端配置項沒有正常加載,求助!!!!!10. 提示語法錯誤語法錯誤: unexpected ’abstract’ (T_ABSTRACT)
