public static class ScriptInjector.FromUrl extends Object
Modifier and Type | Method and Description |
---|---|
JavaScriptObject |
inject()
Injects an external JavaScript reference into the document and optionally
calls a callback when it finishes loading.
|
ScriptInjector.FromUrl |
setCallback(Callback<Void,Exception> callback)
Specify a callback to be invoked when the script is loaded or loading
encounters an error.
|
ScriptInjector.FromUrl |
setRemoveTag(boolean removeTag) |
ScriptInjector.FromUrl |
setWindow(JavaScriptObject window)
This call allows you to specify which DOM window object to install the
script tag in.
|
public JavaScriptObject inject()
public ScriptInjector.FromUrl setCallback(Callback<Void,Exception> callback)
Warning: This class does not control whether or not a URL has already been injected into the document. The client of this class has the responsibility of keeping score of the injected JavaScript files.
Known bugs: This class uses the script tag's onerror()
callback to attempt to invoke onFailure() if the
browser detects a load failure. This is not reliable on all browsers
(Doesn't work on IE or Safari 3 or less).
On Safari version 3 and prior, the onSuccess() callback may be invoked even when the load of a page fails.
To support failure notification on IE and older browsers, you should check some side effect of the script (such as a defined function) to see if loading the script worked and include timeout logic.
callback
- callback that gets invoked asynchronously.public ScriptInjector.FromUrl setRemoveTag(boolean removeTag)
removeTag
- If true, remove the tag after the script finishes
loading. This shrinks the DOM, possibly at the expense of
readability if you are debugging javaScript.
Default value is false
, but this may change in a future
release.public ScriptInjector.FromUrl setWindow(JavaScriptObject window)
builder.setWindow(ScriptInjector.TOP_WINDOW);
window
- Specifies which window to install in.Copyright © 2018. All rights reserved.