


Detailed explanation of examples of dynamically loading pages and executing them
ExtJS 4.1 TabPanel dynamically loads the page and executes the script. It took me several days to write this thing, but after finishing it, I will have a full sense of accomplishment. I finally succeeded. I am very excited. I will tell you about it below. Introducing my entire process of writing code.
According to the official example, the page can be loaded dynamically, but the script is not executed, so I checked the SDK and Google and found that scripts needs to be set to true, so I set this attribute. The entire code is as follows
tabPanel.add({ title: 'dynamic page', closable: true, loader: { 'test.htm', loadMask: 'loading...', autoLoad: true, scripts: true } });
Just started I thought there was something wrong with the script for loading the page, because after checking a lot of information, some people said it should be written in the
, while others said it could only be written on the page and could not use src to reference the js file, but no matter how hard I tried, it didn't work. My loading page is very simple. As long as the page is loaded, a pop-up window will pop up.<script type="text/javascript"> alert("addd"); </script> 后来想,是不是需要在tab被激活的事件手工load,而不是autoLoad,于是再次实验,终于成功了,兴奋! tabPanel.add({ title: 'dynamic page', closable: true, loader: { 'test.htm', loadMask: 'loading...', autoLoad: true, scripts: true } listeners: { activate: function(tab){ tab.loader.load(); } } });
I originally thought that this would be the end of it, and I would finally finish this tab in one day, but when I was excited, I discovered that there was a problem with this approach. Every time Every time a tab is clicked, an activation event will be triggered to read the background page once. The effect I want is that after the frontend is loaded once, switching tabs does not require access to the background again. So I checked the SDK and Google, and wanted to judge that the tab has been loaded in the activate event, but failed
The next day, I removed the listeners, and then inexplicably wanted to test the loading effect of the loaded page, deliberately blocking the page thread, and adding The following code
System.Threading.Thread.Sleep(5000);
This time it was unintentional. I found that the page loaded after 5 seconds could actually execute the script normally!
My steps are as follows: click the load button, and then click the dynamically loaded tab. The tab has no content. After 5 seconds, the content appears and the script is executed.
But the page is loaded I can't always sleep, so I continue to check the information and continue to try, and even start to debug the source code of extjs. Here is how to debug, and the page switches to the following script
<script type="text/javascript" src="/Scripts/ext/ext-all.js?1.1.11"></script>改为 <script type="text/javascript" src="/Scripts/ext/ext-debug.js?1.1.11"></script>
I won’t explain how to debug, there are many googles, I spent a day debugging, to no avail. However, this is my first close contact with the extjs code
and I also discovered a strange thing. During debugging, even if Sleep(5000) is added, the loaded page script cannot be executed. , I became more and more puzzled
On the third day, I joined QQ groups like crazy, posted on various forums and websites, and continued to google, but to no avail
On the fourth day, I was lucky enough to use Microsoft Bing to search autoload:true, scripts:true, the first article comes out, there is such an introduction, but it is about extjs How does the 4.0 panel load the page and execute the script, so I tested it according to its code
Ext.onReady(function () { var panel = Ext.create('Ext.Panel', { title: 'Anchor Layout', renderTo:Ext.getBody(), loader:{ url: "test.htm",autoLoad:true, scripts:true}//加载1.htm页面 }); });
The code can be executed successfully! I was completely excited now, because the tab can load any component, and of course it can also load the panel, so I modified my code
var panel = Ext.create('Ext.Panel',{ title: 'dynamic page', renderTo:Ext.getBody(), closable: true, loader: { 'test.htm', loadMask: 'loading...', autoLoad: true, scripts: true } }); tabPanel.add(panel);
successfully! I'm really ecstatic. After spending 4 days, I finally got a good result. This kind of joy can only be understood by our technical staff.
Comparing the code differences, I found that there is one missing configuration, which is the yellow color above me. The marked one, renderTo:Ext.getBody(), actually needs to be rendered before the script can be displayed normally. Why is there no SDK! !
But, but...this is not a perfect solution. Careful friends will know that the script will load the loading page first to the main page, and it will disappear after switching tabs. Such a serious problem, Because I was so excited at the time, I didn’t notice it, alas.
I had to stop typing on the keyboard and think about it carefully. I successfully loaded the page and executed the script three times. These three times were
1 and the tab was activated
2. After sleeping, click tab and wait for the page to load
3. Add renderTo configuration
After thinking for a long time, I finally found that these three successes all had one thing in common. , the loaded page is displayed, that is to say, if the tab loads the page first and then is "seen", the script will not be executed.
In order to verify my idea, I immediately started testing and put Set sleep to 100 milliseconds, click the load button, and then look at the loaded tab after 1 second. Sure enough, the script is not executed! ! !
Finally found the reason: tab must be "shown" first, and then load, then this is easy, check the SDK immediately, it is not difficult to find the show method, so modify the code
tabs.add({ title: 'dynamic page', //renderTo: Ext.getBody(), loader: { url: 'test.htm', loadMask: 'loading...', autoLoad: true, scripts: true } }).show();
OK, the script executes normally, and my problem is "perfectly" solved
The above is the detailed content of Detailed explanation of examples of dynamically loading pages and executing them. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment