怎样实现用存为本地的html离线填报到其他服务器

需求描述

实现离线填报实现存为本地的html,提交时提交到另一个服务器。

需求实现

在showReport.jsp中添加如下Javascript代码,

function _saveToLocal1( table, name ) {

if( ! _submitEditor( table ) ) return;

var html = new StringBuffer();

html.append( “<html>\n<body>\n” );

html.append( “<script language=javascript>” );

if( eval( table.id + “_validOnSubmit” ) ) {

html.append( “var ” ).append( table.id ).append( “_validOnSubmit = true;\n” );

}

else html.append( “var ” ).append( table.id ).append( “_validOnSubmit = false;\n” );

html.append( “var isLineoff = true;\n” );

html.append( “</scr” ).append( “ipt>\n” );

html.append( _getScriptFunctions() );

var div = document.getElementById( “div_” + table.id );

if( div != null ) html.append( div.outerHTML + “\n” );

else html.append( document.body.innerHTML + “\n” );

html.append( “<SCRIPT language=javascript>\n” );

html.append( “\tvar batImport = document.location.href.indexOf( \”?batImport\” ) > 0;\n” );

html.append( “\tvar resultInfoPage = parent.location.href.substring( 0, parent.location.href.lastIndexOf( \”/\” ) ) + \”/getResultInfo.html\”;\n” );

html.append( “\tif( batImport ) _submitTable( ” + table.id + “, resultInfoPage );\n” );

html.append( “</SCR” + “IPT>\n” );

html.append( “</body>\n</html>” );

var htmls1 = html.toString();

var htmls = htmls1.replace(/127.0.0.1:6001/g,”192.168.0.158:10001″);

var pos1 = htmls.indexOf( “id=” + table.id + “_style” );

var pos3 = htmls.indexOf( “styleSheet.addRule(“, pos1 );

if( pos3 > 0 ) {

pos3 = htmls.lastIndexOf( “<SCRIPT”, pos3 );

var pos2 = htmls.indexOf( “</SCRI”, pos3 );

htmls = htmls.substring( 0, pos3 ) + htmls.substring( pos2 + 9 );

}

while( true ) {

pos1 = htmls.indexOf( “id=my___select onmouseover=”, pos1 );

if( pos1 < 0 ) break;

pos1 = htmls.lastIndexOf( “<TABLE”, pos1 );

var pos2 = htmls.indexOf( “</TABLE>”, pos1 );

htmls = htmls.substring( 0, pos1 ) + htmls.substring( pos2 + 8 );

}

try {

eval( “isLineoff” );

pos1 = htmls.indexOf( table.id + “_submitForm” );

pos1 = htmls.lastIndexOf( “<FORM “, pos1 );

pos1 = htmls.indexOf( “action=”, pos1 );

pos3 = htmls.indexOf( ” “, pos1 );

htmls = htmls.substring( 0, pos1 ) + “action=” + table.offSvr + htmls.substring( pos3 );

document.write(htmls);

document.execCommand(“SaveAs”,false,name);

document.close();

}catch( exception ) {

var form = eval( table.id + “_saveToLocalForm” );

form.fileContent.value = htmls;

form.saveAsName.value = name;

form.submit();

form.fileContent.value = “”;

}

}

代码是修改的自动生成的js,修改如下两处,实现替换ip地址,

var htmls1 = html.toString();

var htmls = htmls1.replace(/127.0.0.1:6001/g,”192.168.0.158:10001″);

然后调用重写的js即可实现保存为本地的html内的ip地址的变更,

<a href=”javascript:_saveToLocal1( report1, ‘/testlixian.html’ )”>保存到本机22</a>

热门文章