Home Java javaTutorial Detailed explanation of examples of dynamically loading pages and executing them

Detailed explanation of examples of dynamically loading pages and executing them

Jul 18, 2017 pm 03:21 PM
extjs javascript

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 }
});
Copy after login

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: &#39;dynamic page&#39;,
closable: true,
loader: { &#39;test.htm&#39;, loadMask: &#39;loading...&#39;, autoLoad: true, scripts: true }
 listeners: { activate: function(tab){ tab.loader.load(); } }
});
Copy after login

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>
Copy after login

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(&#39;Ext.Panel&#39;, {
  title: &#39;Anchor
Layout&#39;,  
  renderTo:Ext.getBody(),  
  loader:{ url: "test.htm",autoLoad:true,
scripts:true}//加载1.htm页面
  });
  });
Copy after login

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(&#39;Ext.Panel&#39;,{
title: &#39;dynamic page&#39;,
renderTo:Ext.getBody(),
closable: true,
loader: { &#39;test.htm&#39;, loadMask: &#39;loading...&#39;, autoLoad: true,
scripts: true }
});
tabPanel.add(panel);
Copy after login

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: &#39;dynamic page&#39;,
//renderTo: Ext.getBody(),
loader: {
url: &#39;test.htm&#39;,
loadMask: &#39;loading...&#39;,
autoLoad: true,
scripts: true
}
}).show();
Copy after login

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!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

How to use insertBefore in javascript How to use insertBefore in javascript Nov 24, 2023 am 11:56 AM

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

See all articles