-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows.xml
483 lines (476 loc) · 19.5 KB
/
windows.xml
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<?xml version="1.0" encoding="UTF-8"?>
<CONTENT TITLE="Windows and Frames" ID="windows">
<P>
The <ICODE>window</ICODE> object (also referred to by <ICODE>self</ICODE>) is "DOM Level 0".
No formal standard for it exists.
</P>
<CONTENT TITLE="How can I disable the back button in a web browser?" ID="disableBackButton" NUMID="4_2">
<P>
You can't. The browser's history cannot be modified. However, you
can use <ICODE>self.location.replace(url);</ICODE> in some browsers to replace
the current page in the history.
</P>
<MOREINFO>
<URL>http://msdn.microsoft.com/en-us/library/ms536712%28VS.85%29.aspx</URL>
<URL>http://docs.sun.com/source/816-6408-10/location.htm#1194240</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I access a frame's content?"
ID="frameRef" NUMID="4_8">
<P>
To reference another frame on the <EM>same domain</EM>:
</P>
<P>
The <DFN>content window</DFN> of a <ICODE>FRAME</ICODE> or <ICODE>IFRAME</ICODE> can be
accessed by the <ICODE>frames</ICODE> collection.
</P>
<P>
Example:
</P>
<CODE>
var fwin;
fwin = self.frames[0]; // or:
fwin = self.frames["iframeName"];
</CODE>
<P>or, from the <ICODE>IFRAME</ICODE> or <ICODE>FRAME</ICODE> element:</P>
<CODE>
var iframeEl = document.getElementById("myFrame");
var fwin = iframeEl.contentWindow; // Nonstandard, but widely supported.
var fdoc = iframeEl.contentDocument; // DOM2 HTML Standard.
</CODE>
<P>
A global identifier <ICODE>moomin</ICODE> in the the iframe's <DFN>content window</DFN>
is accessed as <ICODE>fwin.moomin</ICODE>.
</P>
<P>
To communicate between frames on <EM>different</EM> domains:
</P>
<P>
Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use
<ICODE>window.postMessage( message[, port], otherDomain);</ICODE>.
</P>
<P>
Example:
<URL>http://jibbering.com/faq/example/postMessage.html</URL>
</P>
<P>
Where <ICODE>window.postMessage</ICODE> is not supported, the <ICODE>window.name</ICODE> property
can be set on the other window, which can poll for updates to that
property using <ICODE>setInterval(checkWinName, 100);</ICODE> where <ICODE>checkWinName</ICODE>
is a function that polls to check the value of
<ICODE>self.name</ICODE>.
</P>
<MOREINFO>
<URL>http://en.wikipedia.org/wiki/Same_origin_policy</URL>
<URL>http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html</URL>
<URL>https://developer.mozilla.org/en/DOM/window.postMessage</URL>
<URL>http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I find the size of the window?" ID="getWindowSize"
NUMID="4_9">
<P>
Here is a detailed explanation of a cross-browser strategy to
find the dimensions of the viewport, excepting all chrome
(excludes scrollbars, etc).
</P>
<P>
We can consider various properties:
</P>
<CODE>
window.innerWidth
document.clientWidth
document.documentElement.clientWidth
document.body.clientWidth
</CODE>
<P>
Of the browsers that have an <ICODE>innerWidth</ICODE> property, most
include scrollbar dimensions. Some versions of KHTML browsers
(including Safari 2) do <EM>not</EM> include scrollbar width.
</P>
<P>
The <ICODE>window.inner*</ICODE> properties are unreliable and not
useful here. We don't want scrollbar dimensions included.
</P>
<CODE> document.clientWidth</CODE>
<P>
Certain versions of KHTML, including Safari 2, have
<ICODE>document.clientHeight</ICODE> and <ICODE>document.clientWidth</ICODE>
properties. Where supported, these rare properties accurately
return the height and width of the viewport, without including
scrollbar dimensions.
</P>
<CODE>
document.documentElement.clientWidth
document.body.clientWidth
</CODE>
<P>
MSHTML (Trident), Firefox (Gecko), Opera (Presto), and Safari
(Webkit) all support <ICODE>clientHeight</ICODE> on <ICODE>document.body</ICODE>
and <ICODE>document.documentElement</ICODE>. The difficulty is figuring out
which one is reliable. In other words which object to get the
<ICODE>clientHeight</ICODE> property from:<ICODE>documentElement</ICODE> or <ICODE>body</ICODE>?
</P>
<P>
What the number returned from either of these properties
represents depends on the environment. The environment includes
the browser, its version, and the rendering mode of the document.
In quirks mode, we'll mostly want to use <ICODE>body.clientHeight</ICODE>
(except for in Safari 2).
</P>
<CODE>document.body.clientHeight</CODE>
<P>
Some environments will return the viewport height. Others will
return <ICODE>0</ICODE>. Yet others will return the <ICODE>clientHeight</ICODE> of
the <ICODE>BODY</ICODE> element.
</P>
<CODE> document.documentElement.clientHeight</CODE>
<P>
This is the more "standard" property for getting the height of
the viewport. It usually "works" in modern browsers in
<DFN>standards mode</DFN>. Notable exceptions include Safari 2 and
Opera <= 9.25, both of which return the <ICODE>clientHeight</ICODE>
of the <ICODE>html</ICODE> <EM>element</EM>. (Oddly, Opera <= 9.25
in standards mode returns the width of the viewport for
<ICODE>documentElement.clientWidth</ICODE>).
</P>
<P>
With the exception of Safari 2, <ICODE>body.clientHeight</ICODE> is reliable
where <ICODE>documentElement.clientHeight</ICODE> is found to be unreliable.
For example, in Safari 3+, Opera, and Mozilla, all in quirks mode,
<ICODE>document.documentElement.clientHeight</ICODE> returns the <ICODE>clientHeight</ICODE>
of the <ICODE>html</ICODE> element (this may seem unsurprising but
it is not what we want).
</P>
<P>
Conversely, <ICODE>document.body.clientHeight</ICODE> will return
the height of the viewport in most cases where
<ICODE>document.documentElement.clientHeight</ICODE> does not. An exception
to that is Safari 2, where <ICODE>documentElement.clientHeight</ICODE>
and <ICODE>body.clientHeight</ICODE> both return the height of their
corresponding element (not what we want).
</P>
<P>
By using a combination of <DFN>Feature Testing</DFN> and <DFN>Capability Testing</DFN>,
the dimensions of the viewport can be strategically retrieved
from the property that works in the environment the script is
running in. The trick is determining which property will give us
the value we want.
</P>
<P>
Since <ICODE>document.clientHeight</ICODE> is reliable where
(rarely) supported, and since browsers that support this property
don't return the viewport dimensions from
<ICODE>document.body.clientHeight</ICODE> or
<ICODE>document.documentElement.clientHeight</ICODE>, this should be the
very first condition:
</P>
<CODE>
// Safari 2 uses document.clientWidth (default).
if(typeof document.clientWidth == "number") {
// use document.clientWidth.
}
</CODE>
<P>
The next strategy is to determine if
<ICODE>document.documentElement.clientHeight</ICODE> property is unreliable.
It is deemed "unreliable" when it is either <ICODE>0</ICODE> or taller
than the viewport.
</P>
<P>
Determining if <ICODE>documentElement.clientHeight</ICODE> is <ICODE>0</ICODE> is easy.
The result is stored in a variable <ICODE>IS_BODY_ACTING_ROOT</ICODE>.
</P>
<CODE>
var docEl = document.documentElement,
IS_BODY_ACTING_ROOT = docEl && docEl.clientHeight === 0;
docEl = null;
</CODE>
<P>
To determine if <ICODE>documentElement.clientHeight</ICODE> returns
a value taller than the viewport, we need a <DFN>Capability Test.</DFN>
</P>
<P>
If we can force <ICODE>documentElement</ICODE> to be very tall
(taller than a normal viewport) we can then check to see if
<ICODE>documentElement.clientHeight</ICODE> returns that "very tall" number.
If it does, then it is unreliable.
</P>
<P>
We can force <ICODE>documentElement</ICODE> to be taller than the viewport
(or any "normal" viewport) by adding a <ICODE>div</ICODE> to the <ICODE>body</ICODE>,
give that <ICODE>div</ICODE> a height larger than any normal monitor,
and then check to see if <ICODE>documentElement.clientHeight</ICODE> is
that high (or "almost" that high, to account for <ICODE>documentElement</ICODE>
having a border).
</P>
<CODE>
// Used to feature test Opera returning wrong values
// for documentElement.clientHeight.
// The results of this function should be cached,
// so it does not need to be called more than once.
function isDocumentElementHeightOff(){
var d = document,
div = d.createElement('div');
div.style.height = "2500px";
d.body.insertBefore(div, d.body.firstChild);
var r = d.documentElement.clientHeight > 2400;
d.body.removeChild(div);
return r;
}
</CODE>
<P>
We can use this function to see if we should use
<ICODE>body.clientHeight</ICODE>, instead. (but only after checking if
<ICODE>document.clientHeight</ICODE> is supported).
</P>
<CODE>
// Safari 2 uses document.clientWidth (default).
if(typeof document.clientWidth == "number") {
// use document.clientHeight/Width.
}
else if(IS_BODY_ACTING_ROOT || isDocumentElementHeightOff()) {
// use document.body.clientHeight/Width.
} else {
// use document.documentElement.clientHeight/Width.
}
</CODE>
<P>
The preceding strategy was developed by Garrett Smith with input
from John David Dalton. A complete and tested example can be found
in APE Library under <ICODE>APE.dom.getViewportDimensions</ICODE>.
Source code:
<URL>http://wayback.archive.org/web/20110814142717/http://dhtmlkitchen.com/ape/build/dom/viewport-f.js</URL>.
APE is publicly released under Academic Free License.
APE home: <URL>http://wayback.archive.org/web/20110628160010/http://www.dhtmlkitchen.com/ape/</URL>.
</P>
<P>
Note: The dimensions cannot be determined accurately until after
the document has finished loading.
</P>
<MOREINFO>
<URL>http://msdn.microsoft.com/en-us/library/ms533566%28VS.85%29.aspx</URL>
<URL>http://developer.mozilla.org/en/DOM/window.innerWidth</URL>
<URL>http://dev.opera.com/articles/view/using-capability-detection/</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I check to see if a child window is open, before opening another?"
ID="isWindowOpen" NUMID="4_10">
<CODE>
var myWin;
function openWin(aURL) {
if (!myWin || myWin.closed ) {
myWin = window.open(aURL,'myWin');
} else {
myWin.location.href = aURL;
myWin.focus();
}
}
</CODE>
<P>
Popup windows cause usability problems and are generally best avoided.
</P>
<MOREINFO>
<URL>https://developer.mozilla.org/en/DOM:window.open</URL>
<URL>http://msdn.microsoft.com/en-us/library/ms533574%28VS.85%29.aspx</URL>
<URL>http://docs.sun.com/source/816-6408-10/window.htm#1201877</URL>
<URL>http://www.useit.com/alertbox/990530.html</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="Why does framename.print() not print the correct frame in IE?"
ID="printFrame" NUMID="4_11">
<P>
IE prints the frame that has focus when you call the print
method <ICODE>frameref.focus();frameref.print();</ICODE>
</P>
<MOREINFO>
<URL>http://msdn.microsoft.com/en-us/library/ms976105.aspx</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I close a window and why does it not work on the first one?"
ID="windowClose" NUMID="4_14">
<P>
If a window was opened by javascript, then it can be closed
without confirmation by using <ICODE>windowRef.close()</ICODE>.
</P>
<P>
Before calling <ICODE>windowRef.close()</ICODE> (or other <ICODE>window</ICODE> methods), make
sure the window reference is not null and its <ICODE>closed</ICODE> property is <ICODE>false</ICODE>.
</P>
<P>
Popup windows cause usability problems and are generally best avoided.
</P>
<MOREINFO>
<URL>http://www.useit.com/alertbox/990530.html</URL>
<URL>#isWindowOpen</URL>
<URL>http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx</URL>
<URL>https://developer.mozilla.org/en/DOM/window.close#Description</URL>
<URL>http://docs.sun.com/source/816-6408-10/window.htm#1201822</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="Why do I get permission denied when accessing a frame/window?"
ID="permissionDenied" NUMID="4_19">
<P>
In the normal browser security model, a script may only access the
properties of documents served from the same domain or IP address,
protocol, and port.
</P>
<P>
Any attempt to access a property in such cases will result in a "Permission
Denied" error. Signed scripts or trusted ActiveX objects can
overcome this in limited situations.
</P>
<MOREINFO>
<URL>http://msdn.microsoft.com/en-us/library/ms533028%28VS.85%29.aspx</URL>
<URL>https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I make a 10 second delay?" ID="setTimeout" NUMID="4_20">
<P>
There is no built-in way to pause execution in javascript such
as a sleep function, but hosts usually provide a method of some
form. Web browsers are designed for event driven programming and
only provide the <ICODE>setTimeout</ICODE> and <ICODE>setInterval</ICODE> functions
to facilitate timed delays. The delay before calling <ICODE>getSnork</ICODE> may
exceed the second parameter to <ICODE>setTimeout</ICODE> and <ICODE>setInterval</ICODE>
due to implementation differences among browsers.
</P>
<P>
To call the function <ICODE>getSnork</ICODE>, approximately 10 seconds
after the function <ICODE>getMoomin()</ICODE> completes, you would do this:
</P>
<CODE>
getMoomin();
setTimeout(getSnork, 10000);
</CODE>
<P>
Script execution is not stopped, and adding <ICODE>getSnufkin()</ICODE> after the
<ICODE>setTimeout</ICODE> line would immediately execute the function <ICODE>getSnufkin</ICODE>
before <ICODE>getSnork</ICODE>.
</P>
<P>
Achieving delays through running a loop of some sort for a pre-defined
period is a bad strategy, as that will inhibit whatever was supposed to
be happening during the delay, including blocking user interation.
</P>
<P>
Other (less event driven) hosts have different wait functions,
such as <ICODE>WScript.Sleep()</ICODE> in the Windows Script Host.
</P>
<MOREINFO>
<URL>http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx</URL>
<URL>http://docs.sun.com/source/816-6408-10/window.htm#1203758</URL>
<URL>http://en.wikipedia.org/wiki/Event-driven_programming</URL>
<URL>faq_notes/misc.html#mtSetTI</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I change print settings for window.print()?"
ID="printSettings" NUMID="4_23">
<P>
In a normal security environment, you can't change anything.
</P>
<P>
Print Stylesheet rules provide options.
</P>
<P>
For IE, <ICODE>ActiveX</ICODE> or Plugin ScriptX and
Neptune from Meadroid to give you more control for Windows
versions of Internet Explorer, Netscape, and Opera.
</P>
<MOREINFO>
<URL>http://www.meadroid.com/scriptx/</URL>
<URL>http://msdn.microsoft.com/en-us/library/ms976105.aspx</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I change the confirm box to say yes/no or default to cancel?"
ID="changeBrowserDialog" NUMID="4_28">
<P>
The buttons on a confirm box cannot be changed, nor can a default
button be specified.
</P>
<P>
Change the question to a statement so that "OK" is suitable as the
default response.
</P>
<P>
Example:
"Would you like us to charge your credit card?" (wrong)
"We will now charge your credit card." (right).
</P>
</CONTENT>
<CONTENT TITLE="How do I prompt a "Save As" dialog for an accepted mime type?"
ID="fileDownload" NUMID="4_33">
<P>
It is not possible with client-side javascript.
</P>
<P>
Some browsers accept the Content-Disposition header, but this
must be added by the server. Taking the form:-
<ICODE>Content-Disposition: attachment; filename=filename.ext</ICODE>
</P>
<MOREINFO>
<URL>http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html</URL>
<URL>http://support.microsoft.com/kb/q260519/</URL>
</MOREINFO>
</CONTENT>
<!-- Can we remove this entry?
http://groups.google.com/group/comp.lang.javascript/msg/c70b57d86300fa91
CONTENT TITLE="I have window.status="Moomin"; why doesn't the statusbar change?"
ID="returnValue" NUMID="4_35">
<P>
When changing the status in an event (e.g. <ICODE>onmouseover</ICODE>) you
should return true from the event. Also a number of browsers
require a short delay before setting the status to overcome their
default behaviour with the statusbar.
<ICODE>onevent="setTimeout('window.status=\'Moomin\'',15);"</ICODE>
</P>
<P>
Many browsers are configured, by default, to disallow scripts from setting
the status bar text. Some browsers don't have such a bar, or don't have it by default.
</P>
</CONTENT-->
<CONTENT TITLE="How do I modify the current browser window?" ID="modifyChrome" NUMID="4_36">
<P>
In a default security environment you are very limited in how much
you can modify the current browser window. You can use
<ICODE>window.resizeTo</ICODE> or <ICODE>window.moveTo</ICODE> to resize or move a
window respectively, but that is it. Normally you can only
suggest chrome changes in a <ICODE>window.open</ICODE>.
</P>
<MOREINFO>
<URL>http://msdn.microsoft.com/en-us/library/ms536651%28VS.85%29.aspx</URL>
<URL>https://developer.mozilla.org/en/DOM:window.open</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I POST a form to a new window?" ID="target" NUMID="4_37">
<P>
Use the target attribute on the form, opening a window with
that name and your feature string in the onsubmit handler of the
FORM.
</P>
<CODE>
<form action="" method="post"
target="wndname" onsubmit="window.open('',this.target);return true;">
</CODE>
<MOREINFO>
<URL>http://www.htmlhelp.com/reference/html40/forms/form.html</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I open a new window with javascript?" ID="openWindow" NUMID="4_42">
<P>
New windows can be opened on browsers that support the
<ICODE>window.open</ICODE> function and are not subject to the action of any
pop-up blocking mechanism with code such as:-
</P>
<CODE>
var wRef;
if(window.open){
wRef = window.open("http://example.com/page.html","windowName");
}
</CODE>
<MOREINFO>
<URL>https://developer.mozilla.org/en/DOM:window.open</URL>
<URL>http://www.infimum.dk/HTML/JSwindows.html</URL>
</MOREINFO>
</CONTENT>
</CONTENT>