Ricardo Saraiva
Ricardo Saraiva

Reputation: 53

Call a js with GET parameters

I need someone to enlighten me. I've seen this:

<script src="http://host.com/file.js?no_forms=1"></script>

What does that means? A GET parameter passed to a javascript file? Into which conditions this can be done? What kind of approach is this?

Any help would be appreciated.

Upvotes: 3

Views: 149

Answers (3)

haim770
haim770

Reputation: 49095

Sometimes the parameter is used simply to prevent client side caching.

It could also be that requesting file.js is actually rewritten as a dynamic call (say script.php?file=file.js&no_forms=1) that is fetching the correct file and using the extra parameter somehow.

Upvotes: 2

TreeNode
TreeNode

Reputation: 482

You can use this

<script src="http://host.com/file.js" no_forms="1"></script>

And

function $_GET(q,s) {
    s = s || window.location.search;
    var re = new RegExp('&'+q+'=([^&]*)','i');
    return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}

And get result

var noForms = $_GET('no_forms');

Upvotes: 0

Ravi Gadag
Ravi Gadag

Reputation: 15861

?no_forms=1 is just a query string parameters. i will just tell the common usage of such things.

  • Used for to avoid caching (get new updated version of JS)
  • Some sort of redirection
  • Even some application usage ideas.

Upvotes: 5

Related Questions