Workarounds that JavaScript code cannot perform in the thinkphp controller

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.