解决FABridge中chrome中不能工作问题(FABridge.js play nice with Chrome)

本文介绍了一个关于FABridge.js在Google Chrome浏览器中出现的问题,并提供了一种解决方法。通过调整FABridge.js中的代码,可以确保其在Chrome等现代浏览器中的正常运行。

FABridge.js play nice with Chrome

Today at work I got an email that said, “The site text editor is broken in Google Chrome. Remember about 3 years ago when you thought FABridge.js was a good idea?” In hindsight I would not have used FABridge. I think the levels of indirection out weigh the ease of use (especially if you need tons of control). Nonetheless I had to fix it. Once I found the bug it was pretty easy to fix. I narrowed the error down to FABridge__bridgeInitialized in FABridge.js. FABridge__bridgeInitialized looks for either an embed or object tag based on the browser type. A check for Chrome did the trick.

In FABridge.js if you change:
if (/Explorer/.test(navigator.appName) || /Konqueror|Safari|KHTML/.test(navigator.appVersion))
to:
if((!(/Chrome/.test(navigator.appVersion))) && ((/Explorer/.test(navigator.appName) || /Konqueror|Safari|KHTML/.test(navigator.appVersion))))

you should be in good shape.

So if you hear FABridge.js does not work in Chrome. Or your JavaScript wrapper to the Flash widget is broken this may solve your challenge.

THERE IS A BETTER WAY TO DO THIS. HERE IT GOES
/**This function searches for the flash dom object that has the flex movie in it.
*In some browsers this is an object tag. In other browsers this is an embed tag.
*We know we have the right thing when we find a dom object with the function getRoot.
**/
function FABridge__bridgeInitialized(bridgeName)
{
var searchStr = “bridgeName=”+ bridgeName;
var flashInstanceWithBridge = null;

var flashInstances = document.getElementsByTagName(”object”);

//search object tag
if (flashInstances.length == 1)
{
flashInstanceWithBridge = flashInstances[0];
}
else
{
for(var i = 0; i < flashInstances.length; i++)
{
var inst = flashInstances[i];
var params = inst.childNodes;
var flash_found = false;

for (var j = 0; j < params.length; j++)
{
var param = params[j];
if (param.nodeType == 1 && param.tagName.toLowerCase() == "param")
{
if (param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0)
{
flashInstanceWithBridge = inst;
flash_found = true;
break;
}
}
}

if (flash_found) {
break;
}
}
}

if(!flashInstanceWithBridge|| !flashInstanceWithBridge[”getRoot”] || !(typeof(flashInstanceWithBridge.getRoot) == “function”) ) //search embed tag if the object tag does not have the needed methods
{
flashInstanceWithBridge = null;

flashInstances = document.getElementsByTagName(”embed”);
if (flashInstances.length == 1)
{
flashInstanceWithBridge = flashInstances[0];
}
else
{
for(var i = 0; i < flashInstances.length; i++)
{
var inst = flashInstances[i];
var flashVars = inst.attributes.getNamedItem("flashVars").nodeValue;

if (flashVars.indexOf(searchStr) >= 0)
{
flashInstanceWithBridge = inst;
}

}
}
}

if(flashInstanceWithBridge)
{
FABridge.attachBridge(flashInstanceWithBridge, bridgeName);
}

return true;
}


原文地址: http://www.timothyhuertas.com/blog/2010/11/30/fabridgejs-play-nice-with-chrome/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值