


JavaScript method to implement web page subpage traversal callback (involving window.frames, recursive functions, function context)_javascript skills
The example in this article describes how JavaScript implements web page subpage traversal callbacks (involving window.frames, recursive functions, and function context). Share it with everyone for your reference. The details are as follows:
Extracted from a pure JavaScript tool program written by myself, it is used to traverse all sub-pages of the current web page and execute iterative callbacks, and the return value of the callback function can be used for result return, helping to reduce closure variables~
Its characteristic is that - only the Window object of the subpage is retrieved during recursive traversal, and the callback function is not executed immediately, but is called back in the ordinary loop structure after the retrieval is completed. This can minimize the memory consumption during recursive calls, simplify the program structure, and make it easy to maintain
Global function Frame_Each( CallBack ):
(function (BOM) { function All_Frames(iWindow) { var _Frames_ = [].slice.call(iWindow.frames, 0); for (var i = 0; i < _Frames_.length; i++) _Frames_ = _Frames_.concat( arguments.callee(_Frames_[i]) ); return _Frames_; } BOM.Frame_Each = function (CallBack) { var Frames = [this].concat( All_Frames(this) ); if (! CallBack) return Frames; for (var i = 0, CBR; i < Frames.length; i++) { try { Frames[i].name; } catch (iError) { continue; } CBR = CallBack.apply(Frames[i], [].slice.call(arguments, 1)); if (CBR === false) break; else if (CBR === undefined) continue; return CBR; } }; })(self);
Usage example:
// 无参数 —— 返回一个数组,包含函数调用所在的 Window 对象及其子页面的 Window,其顺序同递归遍历 var Pages = Frame_Each(); console.log( Pages.length ); // 定义回调 —— 回调返回值功能与普通循环语句的对应: // 1. undefined:continue // 2. false:break // 3. 其它任何值:break && return Value var Search_Result = Frame_Each(function () { var iFocus = this.document.activeElement; switch ( iFocus.tagName.toLowerCase() ) { case 'body': return false; case 'iframe': return; } return iFocus; }); Search_Result.innerHTML = 'Hello, Focus!';
I hope this article will be helpful to everyone’s JavaScript programming design.

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

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.

The browser cannot open the web page but the network is normal. There are many possible reasons. When this problem occurs, we need to investigate step by step to determine the specific cause and solve the problem. First, determine whether the webpage cannot be opened is limited to a specific browser or whether all browsers cannot open the webpage. If only one browser cannot open the web page, you can try to use other browsers, such as Google Chrome, Firefox, etc., for testing. If other browsers are able to open the page correctly, the problem is most likely with that specific browser, possibly

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

How to solve the problem of web pages not opening With the rapid development of the Internet, people increasingly rely on the Internet to obtain information, communicate and entertain. However, sometimes we encounter the problem that the web page cannot be opened, which brings us a lot of trouble. This article will introduce you to some common methods to help solve the problem of web pages not opening. First, we need to determine why the web page cannot be opened. Possible reasons include network problems, server problems, browser settings problems, etc. Here are some solutions: Check network connection: First, we need

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

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

Executing PHP code in a web page requires ensuring that the web server supports PHP and is properly configured. PHP can be opened in three ways: * **Server environment:** Place the PHP file in the server root directory and access it through the browser. * **Integrated Development Environment: **Place PHP files in the specified web root directory and access them through the browser. * **Remote Server:** Access PHP files hosted on a remote server via the URL address provided by the server.
