Call appropriate script based on url parameter

178
March 09, 2018, at 02:37 AM

I want to call appropriate script in other php pages based on url ie:

sitename.com/sitepage?script1 > This would call script in script1.php

sitename.com/sitepage?script2 > This would call script in script2.php

sitename.com/sitepage?script3 > This would call script in script3.php

Etc (if nothing than run nothing)

Below I can read pathname after ?. I know how to call script based on get element. How to you run script in php based on url (without specifying if url is xxxxx)

$(document).ready(function () {
 var pathName = window.location.pathname;     
var pageName = pathName.substr( pathName.lastIndexOf("?") + 1 );
    )}

An example of the intention is:

url sitename.com/sitepage?script1 is opened script on this page reads ?script1 now any script in script1.php is run

Answer 1

This seems like it would open you up to script injections very easily, but this would be how I would add scripts based on URL.

$(document).ready(function () { 
  var scriptLocation = window.location.search.substring(1); 
  $(document.body).append($("script").attr("src",scriptLocation)); 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Rent Charter Buses Company
READ ALSO
Kendo Grid Filter on Multiple columns

Kendo Grid Filter on Multiple columns

I am using Kendo Grid For JqueryRequirement is to filter on multiple columns

235
Having trouble making one JQuery variable depend on another

Having trouble making one JQuery variable depend on another

I have a variable called IndependentVar1random that has 2 possible values (A or B)If the IndependentVar1random is "A", I want DependentVar1random to equal either 'a' or 'aa'

191
Cannot write correctly JQuery .load()

Cannot write correctly JQuery .load()

I have some problems withload() I have table in html with list of printers(ip -ddresses) and would like to add the extra column where to get current status of toner

155