I have searched all over the internet to run a function from URL and found out it is not possible.
I am asking if there is another way to do this. I will explain below what I am trying to achieve.
On my website I have several functions that when a hyperlink is clicked on that cracks.php page, the main content changes accordingly. Now I want to direct people from a single URL to that cracks.php page with the function already called. Example - www.example.com/cracks.php?AC ( which will call a function named AC and the content changes before the page loads)
Ive found this method below, but couldnt get it to work.
if(document.location.search == '?AC')
{
AC();
}
Sorry for the messy code on the website. Thanks for reading, any help would be appreciated.
You can call
www.example.com/cracks.php?do=AC
and then getdo
with$doMethod = $_GET['do'];
. What you then do is, use aswitch
function or a fewif
s to check and execute when e.g.$doMethod
equalsAC
.Like this:
That depends if you need to do that dynamically or you can do it hard coded. Because that hard coded is too simple (with if's and switches), what you have to do is:
Then call your_file_name.php?f=func1 and your_file_name.php?f=func2 and you'll see different outputs.
With the help of Mark Koopman I managed to use his Javascript method and it worked like I wanted.
So heres the method in Javascript: