从另一个网站调用java脚本函数 [英] Call a java-script function from another website

查看:69
本文介绍了从另一个网站调用java脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个javascript函数如下:



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

函数SaySomethingToUnity(value)
{
u.getUnity()。SendMessage(GUI,ChangeText,value);
}
- >

< ; / script >







i想要调用并将参数发送到上面的js方法 SaySomethingToUnity 作为url参数。

作为示例https://www.google.lk/search?q=test我可以传递这样的参数。



我希望将参数传递到我的SaySomethingToUnity js函数中,例如:www.mytest.com

解决方案

我找到了来自

 http://stackoverflow.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 >


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://stackoverflow.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>


这篇关于从另一个网站调用java脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆