日期:2014-05-16  浏览次数:20379 次

利用iframe解决js跨越访问
js跨越访问解决方法之一:

上次文奇培训时提到了,利用在url后面加#来解决跨越的问题,我在开发中使用了一种类似的方法。

cc应用中嵌套辅助计费页面,在辅助计费页面调用handle.jsp中的js方法就会涉及到js的跨越问题,直接调用父页面方法时,由于跨越提示没有权限。

可以通过加iframe,iframe的src指向cc应用下的页面来实现


解决方法:

在index.jsp中加一个iframe,iframe的src为cc应用中的一个中间页面,该页面只调用handle.jsp的js方法。

handle.jsp:(cc)


js代码
    tabs[4] = ['','辅助计费','http://localhost:8080/CallCenterProject?basePath=<%=basePath%>','辅助计费'];
 

index.jsp:(辅助计费)

html代码
    <pre name="code" class="html"><iframe id="mframe" style="display: none" src=""></iframe>  
      
    </pre>  


js代码

    $("#mframe").attr("src",$("#basePath").val()+"/hollycrm/priceFrame.jsp?sCity="+departureCity+"&aCity="+destinationCity  
                    +"&transport="+transport+"&weight="+curWeight+"&strVolume="+curVolume+"&insurance="+insured);  


priceFrame.jsp:(cc)

js代码
    <script type="text/javascript">  
        
      window.onload=function(){  
            var orderInfo = {};  
        orderInfo['leavedCityId'] = '${param.sCity}';   
        orderInfo['sendCityId'] = '${param.aCity}';  
        orderInfo['transportMode'] = '${param.transport}';  
        orderInfo['weight'] = '${param.weight}';  
        orderInfo['strVolume'] = '${param.strVolume}';  
        orderInfo['insuredAmount'] = '${param.insurance}';  
            try {  
            parent.parent.tpPageID2.detailf.publishPrice(orderInfo);  
                parent.parent.clickOrderTab();  
            } catch(e) {  
            }  
      }  
      </script>