This example describes a workaround that JavaScript code in the thinkphp controller cannot perform. Share to everyone for your reference. The specific methods are as follows:
Here example analysis of thinkphp in the controller of the Web page special effects code can not execute the solution, take the "exit" this item, my "Exit System" link is written to the left of the frame, with JS dynamically generated. In other words, it cannot be specified by target in the link.
Copy Code code as follows:
$this->assign (' Jumpurl ', __url__. /login ');<br> $this->success ("Logout successful!") ");
This writing, to jump the page is displayed in the right frame, the JS code to write to the URL does not, I put the two lines of code commented out. Direct use:
Copy Code code as follows:
echo "<script>window.top.location.href= ' $url ';</script>";
This is not possible, on the one hand, the URL can not use __app__ these constants, on the other hand, the final implementation of the result is actually the <script> label removed, the remaining direct output!
Copy Code code as follows:
(window.top.location.href= ' index/login ';)
I checked the success function in the action class and didn't find the relevant parameters.
Then suddenly think of a problem, TP in the tags are in angle brackets (<>) to contain, I wrote in the controller <script> is not as a label to parse it? So I wrote the second piece of code again:
Copy Code code as follows:
Echo ' <literal><script>alert ("exit Success"); top.location.href= "Login";</script></literal> ";
That's fine.
I hope this article will be helpful to everyone's thinkphp framework program design.