This article mainly introduces the solution that the JavaScript code in the thinkphp controller cannot execute, and uses the thinkphp <literal> tag to solve the problem that the JavaScript tag is resolved, it is very practical technique, A friend you need can refer to the following
This example describes a workaround that the JavaScript code in the thinkphp controller cannot perform. Share to everyone for your reference. Here's how:
Here is an example of thinkphp in the controller of the Web page effect code can not execute the solution, take "exit" this one, my "Exit System" link is written to the left frame, with JS dynamic generation. In other words, the target cannot be specified by the link.
Copy the Code code as follows:
$this->assign (' Jumpurl ', __url__. /login ');<br> $this->success ("Logout succeeded! ");
In this case, to jump to the page is displayed in the right frame, the JS code to write to the URL is not, I put these two lines of code commented out. Direct use:
Copy the Code code as follows:
echo "<script>window.top.location.href= ' $url ';</script>";
This also does not, on the one hand the URL inside cannot use __app__ These constants, on the other hand, finally executes out the result is unexpectedly the <script> label to remove, the remaining direct output!
Copy the Code code as follows:
(window.top.location.href= ' index/login ';)
I checked the success function in the action class and did not find the relevant parameters.
Then suddenly think of a problem, TP tags are in angle brackets (<>) to contain, I write in the controller <script> is not considered as a label to parse it? So I re-wrote the second piece of code:
Copy the Code code as follows:
Echo ' <literal><script>alert ("Exit succeeded"); top.location.href= "Login";</script></literal> ";
That's all.