|
楼主 |
发表于 2013-9-17 11:34:59
|
显示全部楼层
index.html文件- <!DOCTYPE html>
- <head>
- <script type="text/javascript" src="jquery-1.9.1.js"></script>
- <script type="text/javascript" src="md5.js"></script>
- <script>
-
- $(window).load(function(){
- if('XDomainRequest' in window && window.XDomainRequest !== null) {
- $.ajaxTransport("+*", function( options, originalOptions, jqXHR ) {
- if (typeof options.crossDomain === 'undefined' || !options.crossDomain) {
- return;
- }
- var xdr;
- return {
- send: function( headers, completeCallback ) {
- xdr = new XDomainRequest();
- var date = new Date().getTime();
- if(options.url.indexOf('?') != -1){
- xdr.open("get", options.url+"&t="+date);
- }else{
- xdr.open("get", options.url+"?t="+date);
- }
-
- xdr.onload = function() {
- if(this.contentType.match(/\/xml/)){
- var dom = new ActiveXObject("Microsoft.XMLDOM");
- dom.async = false;
- dom.loadXML(this.responseText);
- completeCallback(200, "success", [dom]);
- } else {
- completeCallback(200, "success", [this.responseText]);
- }
- };
- xdr.onprogress = function() {};
- xdr.ontimeout = function(){
- completeCallback(408, "error", ["The request timed out."]);
- };
- xdr.onerror = function(){
- completeCallback(404, "error", ["The requested resource could not be found."]);
- };
- xdr.send();
- },
- abort: function() {
- if(xdr) xdr.abort();
- }
- };
- });
- }
- jQuery.support.cors = true;
- });
- // 全局变量,记录X5 bsessionid
- var _x5_session_id = null;
- // X5登录的请求URL
- var X5_LOGIN_URL = 'http://192.168.1.102:8080/x5/UI/demo/actions/process/integration/x5Login.j';
- // X5注销的请求URL
- var X5_LOGOUT_URL = 'http://192.168.1.102:8080/x5/UI/demo/actions/process/integration/x5Logout.j';
-
- // 登录并返回bsessionid,判读前一个bsessionid是否过期,过期则重新登录
- function x5Login(username, password, oldSessionID) {
- var newSessionID = null;
- var request = $.ajax({
- crossDomain : true,
- async: false,
- dataType: 'json',
- url: X5_LOGIN_URL,
- data: {
- username: username,
- password: hex_md5(password),
- bsessionid: oldSessionID
- },
- });
- request.done(function(result) {
- if (result.flag) {
- newSessionID = result.bsessionid;
- _x5_session_id = newSessionID;
- } else {
- alert('登录失败:' + result.message);
- };
- });
-
- request.fail(function(jqXHR, textStatus) {
- alert( "请求失败: " + textStatus );
- });
- return newSessionID;
- }
- // 注销
- function x5Logout(bsessionid) {
- var request = $.ajax({
- crossDomain : true,
- async: false,
- dataType: 'json',
- url: X5_LOGOUT_URL + '?bsessionid=' + bsessionid,
- data: {},
- });
- request.done(function(result) {
- if (result.flag) {
- alert("X5注销成功!");
- } else {
- alert('注销失败:' + result.message);
- };
- });
- request.fail(function(jqXHR, textStatus) {
- alert( "请求失败: " + textStatus );
- });
- }
- // 页面关闭时注销
- $(window).unload(function() {
- if (_x5_session_id == null && _x5_session_id == '') {
- x5Logout(_x5_session_id);
- }
- });
- // 登录按钮click
- function btnLoginClick() {
- // 从页面获取用户名、密码
- var username = $('#username').val();
- var password = $('#password').val();
- _x5_session_id = x5Login(username, password, _x5_session_id);
- $('#x5SessionID').val(_x5_session_id);
- }
- // 注销按钮click
- function btnLogoutClick() {
- x5Logout(_x5_session_id);
- }
-
- // 打开页面按钮click,在iFrame中打开一个X5功能页面
- function btnOpenClick() {
- // 从X5功能页面URL
- var url = $('#wURL').val();
- if (_x5_session_id != null && _x5_session_id != '') {
- // 在页面URL的后面加上bsessionid
- url = (url.indexOf('?') == -1) ? url + '?bsessionid=' + _x5_session_id : url + '&bsessionid=' + _x5_session_id;
- // 在iFrame中打开
- $('#x5Iframe').attr('src', url);
- }
- }
-
- function closeX5Window() {
- alert('由外层决定如何关闭X5Window');
- $('#x5Iframe').attr('src', '');
- }
- </script>
- </head>
- <body style="">
- 用户:<input id="username" value="system"/> 密码:<input id="password" value="123456"/> x5SessionID:<input id="x5SessionID" value="" style="width: 300px"/>
- <button id="btnLogout" onclick="btnLoginClick();">登录</button>
- <button id="btnLogout" onclick="btnLogoutClick();">注销</button>
-
-
-
-
- 页面:<input id="wURL" value="http://192.168.1.102:8080/x5/UI/demo/actions/process/integration/staticActivity1.w" style="width: 600px"/>
- <button id="btnOpen" onclick="btnOpenClick();">打开功能页面</button>
-
- <iframe id="x5Iframe" style="width:100%;height:300px;" onload="this.contentWindow.justep.Portal.closeWindow = closeX5Window;"></iframe>
-
-
-
- </body>
复制代码 |
|