Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 84 lines (58 sloc) 2.551 kB
1568e97 no message
MarcusReimann authored
1 #format dojo_rst
2
3 dojo.withDoc
e2f9ca9 no message
jaredj authored
4 ===============
1568e97 no message
MarcusReimann authored
5
e2f9ca9 no message
jaredj authored
6 :Available: since V0.9
1568e97 no message
MarcusReimann authored
7
8 .. contents::
9 :depth: 2
10
11b836e no message
jaredj authored
11 dojo.withDoc provides a mechanism by which a function can have the document root temporarily changed for the execution of the function. This allows document scope changes without affecting other items in the current dojo application.
1568e97 no message
MarcusReimann authored
12
13 ============
14 Introduction
15 ============
16
e2f9ca9 no message
jaredj authored
17 This function provides a quick way to alter the 'document' root as seen by dojo for specific operations. This is most notably useful when iframes are involved and you want to use a core dojo function, such as dojo.query or dojo.style against contents of that iframe.
1568e97 no message
MarcusReimann authored
18
19 =====
20 Usage
21 =====
22
a916db6 no message
jaredj authored
23 Use this function to replace the dojo.doc reference for a specific function call. Only during that specific function execution is dojo.doc assigned the document you specify. The below example demonstrates how to use it against an iframe document to query into the iframe and make updates.
1568e97 no message
MarcusReimann authored
24
25 .. code-block :: javascript
26 :linenos:
27
28 <script type="text/javascript">
ed82d59 no message
jaredj authored
29 var iframeDoc = dojo.byId("someFrameId").contentWindow.document;
1568e97 no message
MarcusReimann authored
30
e2f9ca9 no message
jaredj authored
31 //Call a callback with different 'global' values and context.
32 dojo.withDoc(iframeDoc function() {
33 var someDiv = dojo.query("someDiv");
34 dojo.style(someDiv, "color", "red");
35 }, this));
36 </script>
1568e97 no message
MarcusReimann authored
37
38
39 ========
93a5fe9 no message
jaredj authored
40 Examples
41 ========
42
43 Example 1: Using dojo.withDoc alter documents in an iFrame.
44 -----------------------------------------------------------
45
46 .. cv-compound ::
47
48 .. cv :: javascript
49
50 <script>
51 dojo.require("dijit.form.Button");
52
53 function changeStyles() {
54 var button = dijit.byId("changeStyles");
55 dojo.connect(button, "onClick", function() {
3445be1 no message
jaredj authored
56
57 //Apply styles to the document contained by the iframe
be0919a no message
jaredj authored
58 var frameDoc = dojo.byId("simpleFrame").contentWindow.document;
93a5fe9 no message
jaredj authored
59 dojo.withDoc(frameDoc, function() {
cdaf089 no message
jaredj authored
60 var tds= dojo.query("td");
61 dojo.forEach(tds, function(cell) {
37f422f no message
jaredj authored
62 dojo.style(cell, "color", "red");
cdaf089 no message
jaredj authored
63 }, this);
93a5fe9 no message
jaredj authored
64 });
65 });
66 }
67 dojo.addOnLoad(changeStyles);
68 </script>
69
70 .. cv :: html
71
9802bcf deprecated attribute replaced
maastermedia authored
72 <button id="changeStyles" data-dojo-type="dijit.form.Button">Change Text Color in iFrame</button>
551d14c no message
jaredj authored
73 <br><br>
4997eab @phiggins42 no message
phiggins42 authored
74 <iframe id="simpleFrame" name="simpleFrame" src="{{dataUrl}}dojox/data/tests/stores/books.html" style="width: 500px; height: 500px;">
93a5fe9 no message
jaredj authored
75 </iframe>
76
77
78
79 ========
1568e97 no message
MarcusReimann authored
80 See also
81 ========
82
e2f9ca9 no message
jaredj authored
83 * `dojo.doc <dojo/doc>`_
Something went wrong with that request. Please try again.