4

BO报表系统嵌入Iframe在firefox下的错误修改

 3 years ago
source link: https://blogread.cn/it/article/1694?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

BO报表系统嵌入Iframe在firefox下的错误修改

浏览:4312次  出处信息

    1. 需求概要

    BO报表嵌入Iframe框架中,在IE下功能正常,firefox下功能错误。

    主要原因,由于BO报表内嵌的frame元素较多,ie和firefox对读取iframe元素的js操作存在差异导致

    解决方法,修改js的相关方法,以达到不同浏览器的兼容

    2. 技术方案

     2.1 具体说明

     2.1.1 utils.js

     2.1.1.1 文件路径

     以businessobjects为项目目录

     businessobjects\\enterprise115\\desktoplaunch\\InfoView\\utils\\utils.js

     2.1.1.2 修改内容

     原方法内容:

     function findElementById(Id) {

     var mywin = window;

     while (mywin != mywin.parent && mywin.parent &&mywin.parent.document) {

     mywin = mywin.parent;

     var f = mywin.document.getElementById(Id);

     if (f != null) return f;

     for (var i = 0; i < mywin.length; i++) {

     f = findElementHelper(mywin.frames[i], Id);

     if (f != null) return f;

     return null;

     修改后的方法内容:

     function findElementById(Id) {

     var mywin = window;

     var curwin = window;

     curwin = mywin;

     while (mywin != mywin.parent

     && mywin.parent &&mywin.parent.document) {

     mywin = mywin.parent;

     curwin = mywin;

     } catch (err) {

     mywin = curwin;

     var f = mywin.document.getElementById(Id);

     if (f != null) return f;

     for (var i = 0; i < mywin.length; i++) {

     f = findElementHelper(mywin.frames[i], Id);

     if (f != null) return f;

     return null;

     2.1.1.3 修改说明

     由于没有嵌套iframe时,ie和firefox的逻辑都是正常的

     嵌套后firefox中mywin != mywin.parent && mywin.parent&&

     mywin.parent.document此语句运行时会出现异常,主要是上级对象的获取错误。

     因此在JS中,在保持原逻辑的情况下,对出现的异常进行捕捉操作。

     如果对象mywin.parent不存在时,直接获取mywin即可。

     2.1.2 IVIntegration.js

     2.1.2.1 文件路径

    以businessobjects为项目目录

     businessobjects\\enterprise115\\desktoplaunch\\viewers

     \\cdz_adv\\scripts\\IVIntegration.js

     2.1.2.2 修改内容

     原方法内容:

     function setDocTitle(strDocName){

     var myframe=self;

     while (myframe.parent && myframe!=myframe.parent){

     myframe=myframe.parent;

     var isAppsFrame=(myframe.thisIsAnAppsFrame

     &&myframe.thisIsAnAppsFrame==”wishYouAreHere”)?true:false;

     if (isAppsFrame) break;

     var isTop=(myframe.thisIsTheIVTopFrame

     &&myframe.thisIsTheIVTopFrame==”wishYouAreHere”)?true:false;

     var fs=myframe.frames;

     if (fs){

     var header=fs[0];

     if (header && header.setTitle){

     header.setTitle(convStr(strDocName));

     break;

     if (isTop) break;

     修改后的方法内容:

     function setDocTitle(strDocName){

     var myframe=self;

     while (myframe.parent && myframe!=myframe.parent){

     myframe=myframe.parent;

     var isAppsFrame=(myframe.thisIsAnAppsFrame

     &&myframe.thisIsAnAppsFrame==”wishYouAreHere”)?true:false;

     }catch(e){

     var isAppsFrame = true;

     if (isAppsFrame) break;

     var isTop=(myframe.thisIsTheIVTopFrame

     &&myframe.thisIsTheIVTopFrame==”wishYouAreHere”)?true:false;

     var fs=myframe.frames;

     if (fs){

     var header=fs[0];

     if (header && header.setTitle){

     header.setTitle(convStr(strDocName));

     break;

     if (isTop) break;

     2.1.2.3 修改说明

     由于BO报表本身就是iframe结构,因此再嵌入iframe页面中,获取指定对象的操作就会变得复杂。

     加之ie和firefox浏览器,在js中对iframe对象的获取方法需要有的兼容性,因此此方法的某些语句在firefox下便会发生错误。

     发生错误的语句为,var isAppsFrame=(myframe.thisIsAnAppsFrame

     &&myframe.thisIsAnAppsFrame==”wishYouAreHere”)?true:false。

     还是保持不改变源程序逻辑基础上进行改进,将出现的异常进行捕捉。

     如果获取这些frame对象出现异常时,定义var isAppsFrame=true即可。

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK