我正嘗試讀取JavaScript文件中的查詢參數。從文件路徑中讀取查詢參數
代碼 -
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat App List</title>
</head>
<body>
<div id="app"></div>
<script src="bundle.js?cid=vivek"></script> // I am trying to read value of cid in bundle.js file
</body>
</html>
到目前爲止,我試圖在包文件中使用window.location.href
但它給undefined
,因爲它從URL讀取和網址提供index.html
文件
哪個查詢參數? – d4rty
檢查此問題http://stackoverflow.com/questions/4716612/how-do-i-get-query-string-value-from-script-path – GBnewbie
嘗試獲取腳本標記的引用並訪問其src 'property – mr5