且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从另一个网站调用java脚本函数

更新时间:2023-01-08 17:13:01

我找到了来自
 http://***.com/questions/2405355/how-to-pass-a-parameter-to-a-javascript-through-a-的解决方案url-and-display-it-a-page 

这里是灵魂:

var GET = {};
var query = window.location.search.substring(1).split(& quot;& amp;& quot;);
for(var i = 0,max = query.length; i & lt; max; i ++)
{
if (query [i] ===& quot;& quot;)//检查尾随& amp; ,没有参数
continue;

var param = query [i] .split(& quot; =& quot;);
GET [decodeURIComponent(param [0])] = decodeURIComponent(param [1] ||& quot;& quot;);
}
用法:GET.Use_id或GET [& quot; Use_id& quot;]。您还可以使用& quot; Use_id& quot;来检查参数是否存在,即使它具有空值。在GET中(将返回true或false)。< / pre &GT; 跨度>


Hi, there is a javascript function in my webpage as following :

<script type="text/javascript" language="javascript">
<!--
//initializing the WebPlayer
var u = new UnityObject2();
u.initPlugin(jQuery("#unityPlayer")[0], "Example.unity3d");

function SaySomethingToUnity(value)
{
    u.getUnity().SendMessage("GUI", "ChangeText", value);
}
-->
</script>




i want to call and send parameters to above js method " SaySomethingToUnity " as url parameter.
as an example " https://www.google.lk/search?q=test " i can pass parameter like this.

like wise i want to pass parameters into my SaySomethingToUnity js function that in eg : www.mytest.com

I was found a solution from
http://***.com/questions/2405355/how-to-pass-a-parameter-to-a-javascript-through-a-url-and-display-it-on-a-page

here is the soultion :

var GET = {};
var query = window.location.search.substring(1).split(&quot;&amp;&quot;);
for (var i = 0, max = query.length; i &lt; max; i++)
{
    if (query[i] === &quot;&quot;) // check for trailing &amp; with no param
        continue;

    var param = query[i].split(&quot;=&quot;);
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || &quot;&quot;);
}
Usage: GET.Use_id or GET[&quot;Use_id&quot;]. You can also check if a parameter is present even if it has a null value using &quot;Use_id&quot; in GET (will return true or false).</pre>