2016-08-05 27 views
0

我有以下網址https://mywebsite/somepage/1234/5678其中somepage是一個頁面的路由和數字是參數。如何使用靜態網頁中的參數處理友好的網址?

我的頁面是一個靜態頁面,只是html和javascript。例如:https://mywebsite/somepage.html

我怎麼能打開這個頁面給定上述網址獲取頁面內的參數?

原因是我有一個移動深度鏈接將用戶指向一個網站,以便它可以下載應用程序,以防它未安裝或應用程序本身。我沒有選擇在CakePHP或Spring框架中使用帶有路由系統的動態頁面。

回答

0

如果你想加載普通頁面(https://mywebsite/somepage.html),那麼你可以使用散列代替。它們不會被服務器看到,所以它會提供常規的html文件。

// get the url 
var url = window.location.href; // = "https://mywebsite/somepage.html#1234/5678" 

// get the bit you want 
var params = url.substring(32); // = "1234/5678" 
//   ^the length of "https://mywebsite/somepage.html#" 

// split it apart into individual parts 
params = params.split("/"); // = ["1234", "5678"] 

// then do whatever you like with the params 
0

/

var urlPath = window.location.pathname.split('/');

創建從目前的路徑拆分陣列做與陣列東西...

urlPath.forEach(function(item) { 
    console.log(item); 
}); 
+0

坦克FO答覆。不幸的是,我收到了404錯誤。 – Natanael

+0

404錯誤不應該是此代碼的結果,因爲它僅僅解析URL路徑。聽起來像是URL或服務器的問題。 –