Skip to content Skip to sidebar Skip to footer

Jquery Get Query String From It's Own (self) Link

Is it possible to have a javascript link like this (notice the query string): and then in myScr

Solution 1:

//to set script do some thing like thisvar version = 3;
document.write('<script type = "text/javascript" src = "/js/myScipt.js?v='+version+'"></script>');
//or 
$("body").append('<script type = "text/javascript" src = "/js/myScipt.js?v='+version+'"></script>');


//to get v from myscript.jsvar getV = document.currentScript.src.split("?v=")[1];
// var getV =  $('script').last().attr("src").split("?v=")[1];

Solution 2:

There is no reason for you to pass information through the link when calling a script. That JavaScript will run after it has been called. There is for sure a better way to do what you are trying to acomplish with this.

Something like this might give you an idea.

var value;
$("script").each(function(){

var temp = "v=";
If(this.src.indexOf(temp) > -1 )) > -1){

get last digits before "&"if any exist.
And after the index of temp var.
}
});

Post a Comment for "Jquery Get Query String From It's Own (self) Link"