Openfire和Strophejs網站功能變數名稱不同如何進行通信,這個問題總算解決,下麵是解決步驟。解決方案一:Chrome瀏覽器預設支持跨域訪問IE瀏覽器需要做配置:點擊IE瀏覽器的的“工具->Internet 選項->安全->自定義級別”將“其他”選項中的“通過域訪問數據源”選中為“啟用”或者“提示...
Openfire和Strophejs網站 功能變數名稱不同如何進行通信,這個問題總算解決,下麵是解決步驟。
location /http-bind/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://A:7070/http-bind/;
}
註:nginx 埠是80,配置後訪問 http://A/http-bind/ 即等同訪問 http://A:7070/http-bind/
1.2 nginx html文件夾中添加crossdomain.xml文件<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all"/> <allow-access-from domain="*" to-ports="5222,5223,7070,7443" secure="true"/> </cross-domain-policy>
2 Web界面添加跨域JS 2.1添加js文件及相關插件 2.2html界面引用跨域js和strophejs
<script src='strophe/strophe.js'></script> <script src='strophe/flXHR.js'></script> <script src='strophe/strophe.flxhr.js'></script>
2.3具體應用
界面引用js<script src='strophe/basic.js'></script>
basic.js具體運用內容如下:
var BOSH_SERVICE = 'http://A/http-bind/'; var domain= 'A'; var connection = null; $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; $('#connect').bind('click', function () { var button = $('#connect').get(0); if (button.value == 'connect') { button.value = 'disconnect'; connection.connect($('#jid').get(0).value+"@"+domain, $('#pass').get(0).value, onConnect); } else { button.value = 'connect'; connection.disconnect(); } }); });
具體下載:http://download.csdn.net/detail/caiping07/9388726