How can I modify this script to work with a 3d object like a cube to open a link in a new tab bypassing popup blockers?
Hi, I used this small piece of javascript code to open external links in an old project, but had to instruct the users to allow popup windows to make it work: var setURL : String = "http://www.google.com";
function OnMouseDown():void {
Application.ExternalEval("window.open('" + setURL + "')");
}
Now I'm trying to make use of the example provided in [https://github.com/valyard/UnityWebGLOpenLink][1]
This are the 3 main files used by this example:
Plugin:
var OpenWindowPlugin = { openWindow: function(link) { var url = Pointer_stringify(link); document.onmouseup = function() { window.open(url); document.onmouseup = null; } } };
mergeInto(LibraryManager.library, OpenWindowPlugin);
Script 1:
using UnityEngine; using System.Runtime.InteropServices;
public class Link : MonoBehaviour { public void OpenLinkJSPlugin() { #if !UNITY_EDITOR openWindow("http://unity3d.com"); #endif }
[DllImport("__Internal")] private static extern void openWindow(string url); }
Script 2:
using UnityEngine; using UnityEngine.EventSystems; using System; using UnityEngine.Events;
public class PressHandler : MonoBehaviour, IPointerDownHandler { [Serializable] public class ButtonPressEvent : UnityEvent { }
public ButtonPressEvent OnPress = new ButtonPressEvent(); public void OnPointerDown(PointerEventData eventData) { OnPress.Invoke(); } }
This example is for making buttons open external links, but I need to transform it in someway that I can attach it to a 3d object like a cube, where I can define the URL to be opened for each element, and make the call to the plugin when the player clicks on the cube.
Thanks in advance for any help!
Regards,
German Acevedo Working on Unity3d 5.3.4f1 Professional Build target: WebGL