Opening ActiveView Override URLs in a new window

A recent post in the OpenText Content Server ActiveView & WebReports forums asked about how to get commands added with an ActiveView Override to open in a new window rather than the same tab. In this article we will look in detail at adding commands using three of the ActiveView Override types and how we can provide links in them that will open in a new browser window.

Main Menu

Starting with the Main menu, I reviewed the standard JavaScript, and traced the code to a function called menu_callback in menu.js as shown below :

screenshot of HTML & JavaScript source

Looking at the source of this JavaScript function, we can see that is does take a second parameter to indicate which window to open the link in, which is passed onto the openURL function :

screenshot of HTML & JavaScript source

However, the population of this JavaScript parameter is not possible directly from the ActiveView Override itself, as the option is not exposed in the current implmentation, so we have to get a little creative. Looking at the format of the HTML I decided to try adding in a partially formatted string to create the appropriate output in the HTML to push a window name into the second parameter of the call (this does result in the current second parameter in the function call provided by the WebLingo being pushed to third in the function - see MDN for how JavaScript handles this. Using this approach we have the following ActiveView Override :

<?xml version="1.0" encoding="utf-8" ?>
    <overrides>
        <override type="topmenu">
            <commands menutype="Personal">
                [// Add a new command to the Personal menu and place in position 2
                <addcommand newcmd="Google" neworder="2" newurl="http://google.com','new"/>
            </commands>
        </override>
    </overrides>

The additional ' in the ActiveView Override newurl parameter - "http://google.com',' new" - is carried into the HTML output and thus creating the change in the HTML we need from shown below and thus the link opens in a new window as required. You can see the differences in the following screenshot :

screenshot of HTML & JavaScript source

Add Item Menu

The next override location to look at is the Add Item menu, again a choice of window is supported in the underlying JavaScript method that is called openURL in ajax_dhtml_util.js, which is the same function called by menu_callback above, as shown in the following screenshot :

screenshot of HTML & JavaScript source

Tracing the population of this HTML back, we end up in the webnode\html\additemcomponent.html file which iterates through the available options and in our case calls the nm_AddNewMenuItemWithUrl function in menu.js which creates the JavaScript for each menu item, and this does not support a standalone window parameter. Thus, we need to tweak the URL parameter to this call so that its passed directly through to the openURL function as shown below :

<?xml version="1.0" encoding="utf-8" ?>
    <overrides>
        <override type="additem">
            <commands>
                [// Example of adding a Google item and placing it in position 1 of the list
                <additem newItem="Google" newOrder="1" newImg="[LL_REPTAG_SUPPORTDIR /]2-guys.gif"r/>newURL="http://www.google.ca\',\'new" />
            </commands>
        </override>
    </overrides>

This time the addition of the \',\' in the newURL attribute provides what we need to shuffle the parameters in the HTML generated at the end of the process in a similar way to the previous change to result in the following HTML fragment being created by the WebLingo and ActiveView Override :

screenshot of HTML & JavaScript source

Function Menu

The final override location is the function menu override, looking at the JavaScript that populates the menu is popup_callback in menu.js and its functional definition indicates that it does support a window parameter function popup_callback( theURL, theTarget ) :

screenshot of HTML & JavaScript source

Again, ActiveView does not support a parameter being passed directly for this JavaScript parameter. A similar approach used above does not work in this case as the URL is encoded as its passed through the various JavaScript functions resulting in the loss of our tweak to insert the additional parameter, so a different approach is needed. Looking at the WebLingo that creates the page, webnode\html\functionsmenu2.html, the property openInNewTab is set as each command is processed in a loop in that WebLingo file ;openInNewTab = data.openInNewTab and this determines if a new window is used or not :

screenshot of HTML & JavaScript source

Tracing further back, the openInNewTab property is part of the WebNodeCommand object, which by default returns the value of the object's .fOpenInNewTab property which is a Boolean.

OpenText Content Server OScript WebNodeCommand object

As we are overriding via ActiveView, which is at a higher level of abstraction, we cant set this property, nor do we have a similar ActiveView parameter that we can populate for new menu items, therefore we move back to seeing what can be achieved by pushing an amended value for the URL parameter through from the ActiveView.

The URL can use the javascript: handler so we are able to set the URL value to javascript:alert("hello world") which shows the message box (assuming Javascript in the address bar is enabled in your browser) :

<addcommand newcmd="Run WebReport" neworder="1" newurl="javascript:alert('hello');" newParent="Main" />

Therefore we can use the JavaScript window.open function to provide a JavaScript URL that will open a new window when clicked on :

<addcommand newcmd="Run WebReport" neworder="1" newurl="javascript:window.open('https://www.greggriffiths.org/livelink/','newwin');" newParent="Main" />

This results in the following HTML fragment being created by the WebLingo and ActiveView Override, while not making use of the theTarget parameter in the popup_callback function it does deliver the same end result :

screenshot of HTML & JavaScript source

Conclusion

Using some simple HTML and JavaScript tricks its possible to have items added via an ActiveView Override open in a different browser window to provide those working with ActiveViews as a way to customise the user interface for their user communities a method to have links open in a new window / tab if required.

If you are interested in getting support for setting a new window into the product, then please support the OpenText Feature Request LLWR-16076.

Website Designed by Adservio Consulting Valid HTML 4.01 Strict    Valid CSS!    Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0