获取被调用的javascript文件上的查询字符串 [英] Get the query string on the called javascript file

查看:106
本文介绍了获取被调用的javascript文件上的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在被调用的javascript文件中使用javascript获取查询参数,如下所示:

Is it possible to get the query parameters with javascript on the called javascript file like this:

// in html
<script src="/file.js?query=string"></script>

// in file.js
console.log(this.location.query)

这有可能,或者我必须使用服务器吗?

Is this possible somehow, or I have to use the server?

推荐答案

不,它不是可能,因为脚本文件在全局JavaScript范围内没有任何表示。您只能在haitaka所示的DOM中找到它的元素,但这是一种高度非标准且当然不推荐的方法将参数传递给脚本。

No, it is not possible, because the script file has no representation within the global javascript scope. You can only find its element inside the DOM as shown by haitaka, but this is a highly non-standard and certainly not recommended way to pass parameters to script.

这篇关于获取被调用的javascript文件上的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆