Often, when I update a JavaScript or CSS file used by a webpage, I will tack on v=<version>
. This helps me track what changes I have made but also forces the browser to get the newest version instead of using cache. Example:
<script src="functions.js?v=1.4"></script>
Is is possible, using JavaScript, to detect any query parameters used? Meaning, could function.js
detect that v
is 1.4
?
Often, when I update a JavaScript or CSS file used by a webpage, I will tack on v=<version>
. This helps me track what changes I have made but also forces the browser to get the newest version instead of using cache. Example:
<script src="functions.js?v=1.4"></script>
Is is possible, using JavaScript, to detect any query parameters used? Meaning, could function.js
detect that v
is 1.4
?
- Well you could parse the version out of the href – Sterling Archer Commented Feb 28, 2014 at 20:11
- This is a duplicate of stackoverflow./questions/7992354/… Look at this page to get the answer. – Pascal Le Merrer Commented Feb 28, 2014 at 20:15
- It's duplicate question: stackoverflow./questions/2976651/… – EAndreyF Commented Feb 28, 2014 at 20:16
- @EAndreyF, not exactly. If the question is about can the script get its own query params, it's not. – dentuzhik Commented Feb 28, 2014 at 20:20
2 Answers
Reset to default 4There's no a specific method for this, but you can inspect the DOM as usual:
var script = document.querySelector('script[src~="function.js"]');
script.src.replace(/.+?v=/, ''); // that's your version
<script id="file-js" src="functions.js?v=1.4"></script>
Code to find all parameters :
var url = document.getElementById('file-js').src;
url = url.replace(/^.*?\?/, '');
var params = url.split('&');
for(var i in params) {
var pair = params[i].split('=');
console.log(pair);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744820402a4595580.html
评论列表(0条)