简体   繁体   English

我们可以从另一个html调用另一个内部javascript函数来调用内部javascript函数吗?

[英]can we call the internal javascript function from another internal javascript function from another html?

Hi I am new to javascript . 嗨,我是javascript新手。 I have a doubt that can we call the internal javascript function from another internal javascript function from another html?? 我怀疑我们能否从另一个html调用另一个内部javascript函数来调用内部javascript函数?

For example: 例如:

consider two html a.html and b.html i want to call b.html javascript function from a.html and i want to pass a parameter. 考虑两个html a.html和b.html我想从a.html调用b.html javascript函数,我想传递一个参数。

a.html a.html

<html>
<head>
<script type="text/javascript">
function abc(variable){
xyz(variable);//where xyz function in b.html
}
</script>
</head>
<body>
</body>
</html>

b.html b.html

<html>
    <head>
    <script type="text/javascript">
    function xyz(variable){
    alert('message::'+variable);
    }
    </script>
    </head>
    <body>
    </body>
    </html>

Is this possible or is there any other way to do this??? 这可能还是有其他方法可以做到这一点???

Yes, it is possible. 对的,这是可能的。

  • You can use html imports 您可以使用html导入
  • XHR, select the script with getElemntsByTagName, and eval its content XHR,选择带有getElemntsByTagName的脚本,并评估其内容
  • parenting 为人父母

I do not recommend any. 我不推荐任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM