重定向时,通过其他页面上的URL调用javascript函数

I need to call a javascript function in index.php when I redirect to index.php from another page with some URL queries.

Here is my actual url: index.php?id=10&func=view. I need to wake up a javascript function which is in index.php with this URL.

You can set a session variable in your php code

$_SESSION["jsload"] = "1";

And then check if the variable is set in the index.php

<?php 
        if ( isset($_SESSION['jsload'])=="1" ) { ?>
        //javascript here
        <?php 
        }
?>

Make sure you use session_start() function on both pages

And unset and destroy the session once used

Look into $_GET parameters.

Then try something like this:

if(isset($_GET['id'])){
 //Whatever code you want to return javascript with i.e. "echo $myJavascriptCode"
}

You could also include a main javascript file in your index page, and have a function that checks if a certain URL parameter exists. Here's one that works (albeit hacky):

if (window.location.search.indexOf('id=') > -1) {
    myFunction();
}

You can use callback js function to call your function when page is loading like the below:

URL: index.php?onload=myCallBack&id=10

And below is javascript code:

 <script type="text/javascript">
  var myCallBack = function() {
    /your code is here
  });
  </script>

Hope this help!!!