Skip to content

Commit 0662961

Browse files
committed
jQuery.htmlPrefilter: add new entry
Fixes gh-727
1 parent 2c3a071 commit 0662961

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

entries/jQuery.htmlPrefilter.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<entry type="method" name="jQuery.htmlPrefilter" return="String">
3+
<title>jQuery.htmlPrefilter()</title>
4+
<desc>Modify and filter HTML strings passed through <a href="/category/manipulation/">jQuery manipulation methods</a>.</desc>
5+
<signature>
6+
<added>1.12/2.2</added>
7+
<argument name="html" type="String">
8+
<desc>The html string on which to operate.</desc>
9+
</argument>
10+
</signature>
11+
<longdesc>
12+
<p>This method rarely needs to be called directly. Instead, use it as an entry point to modify existing <a href="/category/manipulation/">jQuery manipulation methods</a>. For instance, to remove all scripts from incoming html strings, do this:</p>
13+
14+
<pre><code>
15+
$.htmlPrefilter = function( html ) {
16+
return html.replace( /&lt;script&#91;^&lt;&#93;*&lt;\/script&gt;/g, "" );
17+
};
18+
</code></pre>
19+
20+
<p>This function can also be overwritten in order to bypass certain edge case issues. The default `htmlPrefilter` function in jQuery will greedily ensure that all tags are XHTML-compliant. This includes anything that looks like an HTML tag, but is actually within a string (e.g. <pre>&lt;a title="&lt;div /&gt;"&gt;&lt;&gt;</pre>). The `jQuery.htmlPrefilter()` function can be used to bypass this:</p>
21+
22+
<pre><code>
23+
$.htmlPrefilter = function( html ) {
24+
// Return HTML strings unchanged
25+
return html;
26+
};
27+
</code></pre>
28+
</longdesc>
29+
<category slug="manipulation"/>
30+
</entry>

0 commit comments

Comments
 (0)