Code: Select all
<script type="text/javascript" src="/js/some-js-file.js?var=foo">Moderator: General Moderators
Code: Select all
<script type="text/javascript" src="/js/some-js-file.js?var=foo">With a javascript file no. But as others have stated you can use a PHP file that outputs the javascript, but what is the difference between what you posted and this?Luke wrote:Let me know if this is possible... I know I've seen GET type variables being passed to javascript files, but I don't know how to access them or how it works. I am almost positive I've seen stuff like this:
But I've never seen how that variable might be accessed from within the javascript file. Is it possible? Or when I've seen this, are they just rendering js files with php or what?Code: Select all
<script type="text/javascript" src="/js/some-js-file.js?var=foo">
Code: Select all
<script type="text/javascript">
var myVar = 'foo';
</script>
<script type="text/javascript" src="/js/some-js-file.js">And... One works and one doesn't.superdezign wrote:Cleanliness, of course.
I usually have one <script> tag:pickle wrote:~AbraCadaver's solution is the cleanest as far as I'm concerned. You're using existing techniques to do the work, rather than hacking your web server, or using PHP to output Javascript.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ext Dev</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/css" />
<script type="text/javascript" src="/scripts"></script>
</head>
<body>
</body>
</html>Code: Select all
<script type="text/javascript" src="/scripts/?var=value"></script>Code: Select all
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}Ok, so assuming that window.location is the location of the requested document, instead of the javascript file that was requested, is there any way to obtain the URI of the javascript file that was requested?VladSun wrote:@Benjamin
It can't work in the OP case.
Searching through DOM for corresponding <script> tag and reading its src attribute?Benjamin wrote: Ok, so assuming that window.location is the location of the requested document, instead of the javascript file that was requested, is there any way to obtain the URI of the javascript file that was requested?