-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.html
79 lines (63 loc) · 2.24 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<title>Docwrite example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript" src="jquery.docwrite.1.2.0.min.js"></script>
</head>
<body>
<h1>Docwrite example</h1>
<div id="example1_element"></div>
<div id="example2_element"></div>
<div id="example3_element"></div>
<div id="example4_element"></div>
<script type="text/javascript"><!--
$(document).bind('beforedocwrite', function(event, data) {
// redirect the write:
data.target = $('#my_element');
// Edit what will be written:
if ( /pattern/.test( data.html ) ) {
data.html = "you can change the text <i>however you like</i>";
};
// Cancel writing:
if ( !confirm("Should we write this:\n" + data.html) )
event.preventDefault();
});
$(document).bind('afterdocwrite', function(event, data) {
alert("'" + data.html + "' was written to " + data.target);
});
//--></script>
<script><!--
var element = document.getElementById('example1_element');
$(element).docwrite( function(arg1, arg2) {
document.write("my <b>html</b> will be appended to $(element)");
}, "passed to function as arg1",
"passed to function as arg2"
);
element = document.getElementById('example2_element');
$(element).docwrite(
"<div>Appended to element</div>\n" +
"<script type='text/javascript'>" +
"document.write('nested document.write()s are handled correctly');" +
"</script>"
);
//--></script>
<script><!--
element = document.getElementById('example3_element');
$(window).load( function() {
document.write("will trigger an event (and be appended to a hidden <div>)");
});
$(element).docwrite( "will not trigger an event" );
//--></script>
<script><!--
element = document.getElementById('example4_element');
$(element).docwrite(
"<script type='text/javascript' ");
$(element).docwrite(
"src='alert.js'></scr"+"ipt>");
$(element).docwrite("<div>Appended to element4</div>" + "<script type='text/javascript'>" + "m='<div>nested '; document.write(m+'");
$(element).docwrite("document.write()s are handled");
$(element).docwrite(" correctly</div>');" + "</scr"+"ipt><div>");
$(element).docwrite('nezhdanchik</div>');
//--></script>
</body>
</html>