Open URL activity in nanoflow

1
I am using open URL activity in nanoflow but it always open URL in the same tab how can  I open URL in new tab?
asked
2 answers
15

You cannot use the OpenURL action from Nanoflow Commons. If you do not have logic to be executed before opening the URL you can use an ‘Open Link’ button on your page.

If you do need logic to be executed before opening the URL, you can create your own OpenURLInNewTab Javascript action. See the example below where I have just slightly altered the OpenURL action from Nanoflow Commons

// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import { Big } from "big.js";

// BEGIN EXTRA CODE
// END EXTRA CODE

/**
 * Opens the provided URL in the web browser in a new tab.
 * @param {string} url - This field is required.
 * @returns {Promise.<boolean>}
 */
export async function OpenURLInNewTab(url) {
	// BEGIN USER CODE
    if (!url) {
        return Promise.reject(new Error("Input parameter 'Url' is required"));
    }
    // Native platform
    if (navigator && navigator.product === "ReactNative") {
        const Linking = require("react-native").Linking;
        return Linking.canOpenURL(url).then(supported => {
            if (!supported) {
                return false;
            }
            return Linking.openURL(url).then(() => true);
        });
    }
    // Hybrid platform
    if (window && window.cordova) {
        window.open(url, "_system");
        return Promise.resolve(true);
    }
    // Web platform
    if (window) {
          window.open(url,'_blank');
        return Promise.resolve(true);
    }
    return Promise.resolve(false);
	// END USER CODE
}

 

answered
2

Lovely. Let's get Mendix to add a SameOrNewTab-parameter to the nanoflow.

answered