Example 1, Example 2 – Adobe Dreamweaver API Reference CS5 User Manual

Page 373

Advertising
background image

368

DREAMWEAVER API REFERENCE

Dynamic documents

Last updated 8/27/2013

Example 1

Assume that the live view content invokes "GetUserName " and use the value populating text element.

Prior to Dreamweaver 13.1

DW code:
function GetUserName()
{
return "SomeName";
}
liveViewBrowser = document.getElementById('browser');
var liveViewDoc = liveViewBrowser.getWindow().document;
liveViewDoc.GetUserName = GetUserName;
Live view browser (<mm:browsercontrol>) code:
document.getElementById("textelement").innerHTML = document.GetUserName();

Dreamweaver 13.1 and later

DW code:
function GetUserName(getUserNameCallbackFunction)
{
getUserNameCallbackFunction("SomeName");
}
liveViewBrowser = document.getElementById('browser');
var liveViewDoc = liveViewBrowser.getWindow().document;
liveViewDoc.GetUserName = GetUserName;
Live view browser (<mm:browsercontrol>) code:
function getUserNameResult(str)
{
document.getElementById("textelement").innerHTML = str;
}
document.GetUserName(getUserNameResult);

Note: Not all synchronous calls can be changed to asynchronous using the approach explained in the example above. In
some scenarios, you may have to consider reducing round trips between two processes. See the next example for another
approach.

Example 2

In the jquery panel, "loadString" is called from the live view browser (<mm:browsercontrol> Render process) to
Dreamweaver. The actual "loadString" JS function just calls dw.loadString to get the localized strings from the
resource. As this is a one-time initialization, you can pass all the necessary strings as part of initializing live view
browser.

Advertising