简体   繁体   English

如何从另一个域调用javascript函数?

[英]how to call javascript function from another domain?

working with a asp.net 3.5 solution with various projects. 在各种项目中使用asp.net 3.5解决方案。 I have a javascript file called MyScript which sits in WebprojectA. 我有一个名为MyScript的javascript文件,它位于WebprojectA中。 What I would like to do is refer to this scriptfile in my WebProjectB? 我想做的是在WebProjectB中引用此脚本文件? example some code in aspx page in WebProjectB: 示例WebProjectB中的aspx页面中的一些代码:

//this script sits in WebProjectA:
    <script src="../Scripts/Myscript.js" type="text/javascript"></script>

Is there anything wrong with doing it like this? 这样做有什么不对吗?

//this script sits in WebProjectB:
    <script src="http://www.webprojecta.com/Scripts/Myscript.js" type="text/javascript"></script>

Your will have to share a common directory structure or reference via a site url. 您将必须通过站点URL共享公共目录结构或引用。 The best approach is to use a CDN. 最好的方法是使用CDN。

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

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