_php instance of a solution that JavaScript code cannot execute in thinkphp controller

Source: Internet
Author: User

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.

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.