【发布时间】:2014-02-20 21:21:36
【问题描述】:
我的HTML块如下,
<html>
<title>Example</title>
<head>
</head>
<body>
<h2>Profile Photo</h2>
<div id="photo-container">Photo will load here</div>
<script type='text/javascript' src='http://example.com/js/coverphoto.js?name=johndoe'></script>
</body>
</html>
我已将此文件保存为test.html。在 JavaScript 源代码中,名称将是动态的。
我想在coverphoto.js 中收集名称。在coverphoto.js中试过,
window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')
但它只获取 html 文件名 (test.html)。如何在coverphoto.js 中从http://example.com/js/coverphoto.js?name=johndoe 检索名称密钥?
【问题讨论】:
标签: javascript get url-parameters