I want use jslib to get url parameter
code like this
jslib
GetUrl: function(){
var s ="";
var strUrl = window.location.search;
var getSearch = strUrl.split("?");
var getPara = getSearch[1].split("&");
var v1 = getPara[0].split("=");
alert(v1[1]);
return v1[1];
},
});
c#
[DllImport("__Internal")]
public static extern string GetUrl();
void Start () {
TextShow.text = GetUrl();
}
When run alert from jslib , I see right string show in alert but UGUI Text shows nothing.
Why did this happen?
To return
string
from Javascript to Unity, you must use_malloc
to allocate memory thenwriteStringToMemory
to copy thestring
data from yourv1[1]
variable into the newly allocated memory then return that.The
writeStringToMemory
function seems to be deprecated now but you can still do the-same thing withstringToUTF8
and proving the size of the string in its third argument.