Home  >  Article  >  Backend Development  >  Solution to the problem that the javascript code in the ThinkPHP controller cannot be executed

Solution to the problem that the javascript code in the ThinkPHP controller cannot be executed

不言
不言Original
2018-06-06 15:01:452498browse

This article mainly introduces the solution to the problem that the javascript code in the ThinkPHP controller cannot be executed. Using ThinkPHP's 242ea1024ad38c613404ea04d9256314 tag to solve the problem of javascript tags being parsed is a very practical technique. Friends who need it can refer to it.

The example in this article describes the solution to the problem that the javascript code in the ThinkPHP controller cannot be executed. Share it with everyone for your reference. The specific method is as follows:

Here is an example analysis of the solution to the problem that thinkphp's web page special effects code in the controller cannot be executed. Let's take the "Exit" item as an example. My "Exit System" link is written The one in the frame on the left is dynamically generated using js. In other words, it cannot be specified through the target in the link.

Copy code The code is as follows:

$this->assign(&#39;jumpurl&#39;,__url__.&#39;/login&#39;);<br>$this->success("注销成功!");

If written like this, the page to be jumped will be displayed in the right frame. Write the js code to It doesn't work in the url, I commented out these two lines of code. Directly use:

Copy code The code is as follows:

echo "<script>window.top.location.href=&#39;$url&#39;;</script>";

This will not work. On the one hand, the constants __app__ cannot be used in the url, on the other hand , the final result of the execution is that the 3f1c4e4b6b16bbbd69b2ee476dc4f83a tag is removed, and the rest is output directly!

Copy code The code is as follows:

(window.top.location.href=&#39;index/login&#39;;)

I checked the success function in the action class and did not find the relevant parameters.

Then I suddenly thought of a question. The tags in tp are all enclosed by angle brackets (a8093152e673feb7aba1828c43532094). Is the 3f1c4e4b6b16bbbd69b2ee476dc4f83a I wrote in the controller parsed as a tag? What's up? So I rewrote the second piece of code:

Copy code The code is as follows:

echo &#39;<literal><script>alert("退出成功");top.location.href="login";</script></literal>&#39;;

That’s it.

Related recommendations:

How Thinkphp distinguishes the mobile terminal and the PC terminal through an entry file

ThinkPHP controller implementation Methods to call each other

The above is the detailed content of Solution to the problem that the javascript code in the ThinkPHP controller cannot be executed. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn