Click on an entity to open a web Overlay


#1

I want to share a simple script that open a web address, specified in the entity User Data as address.
Create or select an existing entity (as a button), add in User Data:

{
  "address": "https://highfidelity.com"
}

the address value, can be what you want (ex: https://youtube.com).
Add this script to the same entity:

(function () {
	function parseJSON(json) {
		try {
			return JSON.parse(json);
		} catch (e) {
			return undefined;
		}
	}	
	function openWebAdress(entityID){
		print("Launching web window");
		var userData = Entities.getEntityProperties(entityID, 'userData').userData;
		var data = parseJSON(userData);
		var webAddress  = data.address;
		var htmlUrl =  Script.resolvePath(webAddress)
		webWindow = new OverlayWebWindow('Test Event Bridge', htmlUrl, 1280, 720, false);	
	}	
	this.clickReleaseOnEntity = function(entityID, mouseEvent) {
        if (!mouseEvent.isLeftButton) {
            return;
        }
        openWebAdress(entityID);
    };
    this.startNearTrigger = function(entityID) {
        openWebAdress(entityID);
    };

});

Enjoy web browsing!