browseEmbed Documentation

BembObject public properties & methods

Properties

Property Accessibility Description
AllowScroll Read/Write Sets the AllowScroll property of the Web Browser control. This helps in making sure scrollbars don’t appear inside your hosted object. Alternatively, use a small margin on the html’s body element. Must be set before Initializing.
Document ReadOnly Returns the HTMLDocument object (equivalent to WebBrowserControl.Object.Document). Applicable only after Initialization.
jQueryNativeVersion Read Only Returns the version of jQuery used in the hosted page (currently all hosted pages require any fairly recent version of jQuery). Applicable only after Initialization.
LastData Read Only Gets the last data posted to the framework’s BembData variable. This is typically filled with: event information for subscribed events, function return values for evaluated functions or custom data specified by your custom JavaScript. Applicable only after Initialization.
SnippetsPath Read/Write Gets or Sets the path to the Snippets file to be used. Can be used before or after Initialization.
SnippetStartQualifier Read/Write Gets or Sets the start qualifier to be used for the Snippets file. Default /// StartSnippet: Can be used before or after Initialization.

Methods

Method Return Type Arguments Description
AddEventHandler N/A Selector, EventName, ReceivingObject, ReceivingMethod, Optional Snippet, Optional OmitQuoteWrap Adds an event listener to the specified element(s) and calls the specified object.method when the JavaScript event is raised. Use the LastData property to get application information on the event.
Eval String CodeToRun, Optional PostFunction Runs the specified code (and optional function to run after the code) and returns the value
EventReceived N/A N/A Do Not Use! This exists as a requirement for the internal Event Handler. Leave this alone…
ExecScript N/A None Executes the specified script
GetSnippet String SnippetName Returns the contents of the specified Snippet, or ZLS if not present. See SnippetsPath and SnippetStartQualifier properties, as well as the Snippets section of this documentation for more information.
Init N/A SubformContainer, URL Initializes the object. Takes the subform that will serve as the object container and the URL to the page to display (current version doesn’t support page navigating).
LoadScriptFileToString String FilePath Loads the contents of a text file into a string. Useful for loading files.

Events

Event Arguments Description
Initialized None Raised after the object and framework are fully initialized. Use this event to set up your event handlers and any other tasks that might require the hosted page to be present.

 

jQuery Integration

Currently (as of v0.5.0.0), jQuery handling is rudimentary but required. The hosted page *must* include some jQuery library of reasonable recency (figure on jQuery 1.7+ being ok, I haven’t fully tested how far back we can go though).

jQuery is required for the event listening and a few other internals of the bemb Framework. The bemb framework creates its own jQuery object called $_bemb. This reference is created by setting it to the jQuery object itself, which is why it’s crucial that jQuery exists in the core html/javascript.

Future plans do involve better support for jQuery, but are currently not implemented. However, you can access the version of jQuery being used through the bemb’s jQueryNativeVersion property.

Snippets

Snippets are a feature of the BembObject that allows you to store bits and pieces of JavaScript code in a dedicated file, without having it loaded into the DOM. Typically it would be used for JavaScript code pieces that would be pulled into VBA before passing them as some of the various Bemb methods.

This serves two purposes: first, it allows us to have “loose” JavaScript code that isn’t loaded into the DOM, so we can store bits and pieces without worrying about negative effects on the DOM, and secondly – if you’ve ever tried to write code for another language inside a different language… yea, not much fun. This lets us write the JavaScript snippets as if it were actually JavaScript instead of having to mess around trying to escape quotes and build ugly strings of JavaScript from within VBA.

How it Works

Quite simply, the Snippets feature points to a file, there’s a specific string used to denote the start of a Snippet (by default: /// SnippetStart: [snippetNameHere]). Everything after that start line, up to the next found start line or the EOF, is returned.

You can change the start line by setting the SnippetStartQualifier property, and you can change the snippets file path by using the SnippetsPath property. Use the GetSnippet()method to get the snippet you need.

Example from ChartJS demo

 

Registry Information

The bemb download package contains two modules that can help with setting up the registry for IE11 Emulation Mode. See the QuickStart page for details.

Notes on setting the registry values:

  • Key: HKCUSoftwareMicrosoftInternet ExplorerMainFeatureControlBROWSER_FEATURE_EMULATION
  • Value: DWORD “msaccess.exe” 11999 (0x2edf or 2edf)
  • The Registry setting can be made under either HKLM or HKCU. HKCU is preferred in that it doesn’t require admin privileges (many thanks to Tom van Stiphout for working this out). The BembRegistry module uses the HKCU hive and is intended as an easy way to run a client location for manual setup.
  • Distribution should be relatively easy, in terms of Registry requirements anyway. One could either use their own little install routine that makes use of the code that’s in the BembRegistry module, or this value could be set as part of an installer’s script.
  • Important! This emulation mode is required to be set for the msaccess.exe executable, which means that any Access programs that may run on this computer will use the emulation mode set here. This shouldn’t generally be a problem, but is definitely worth keeping in mind. In a worst case scenario, you may want to include code to remove/reset the value on your application shutdown. In an absolute worst case scenario, you may want to create an executable wrapper which calls your Access program and enter the Registry value under that executable name (note: I have not tried this and am not sure it will work).