JunChen Wu / 杂记

安装sp2后,原flash的设为首页的js失

写于 2005年01月25日 18:17

今天正巧碰到这个问题。在flash里面做一个设为首页的按钮。
按照以前的思路,有两种做法:
1、直接用getURL调用js
2、使用fscommand

这两种办法在这个帖子里:
http://www.riacn.com/bbs/showthread.asp?threadid=11
见第21条。

要值得注意的是第二种fscommand办法,原文讲的不详细,还有错别字。
我把最新版本flash publish后的script帖出来:

<script language="javascript">
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.

function top_menu_DoFSCommand(command, args) {
var top_menuObj = isInternetExplorer ? document.all.top_menu : document.top_menu;
if (command == "setHomePage") {
document.links[0].style.behavior = "url(#default#homepage)";
document.links[0].setHomePage(args);
} else if (command == "addFavorite") {
args = args.split("|");
window.external.AddFavorite(args[0], args[1]);
}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
document.write(<script language=\"VBScript\"\>\n);
document.write(On Error Resume Next\n);
document.write(Sub top_menu_FSCommand(ByVal command, ByVal args)\n);
document.write( Call top_menu_DoFSCommand(command, args)\n);
document.write(End Sub\n);
document.write(</script\>\n);
}
</script>

在这个函数里面,top_menu是swf文件的名字,如果不改过来,那么该函数也会失效。比如你的swf文件是aaa,那么要写成aaa_DoFSCommand,top_menuObj也写成aaaObj,其他的类推。

当没有语法问题后,如果你的XP打了sp2补丁,那么浏览的时候应该会显示错误并且提示没有权限(当然添加到收藏夹是可以的)。目前我知道有数台xp sp2系统的电脑都会这样失效。所以猜测是sp2安全性问题。初步判断是红色那行的权限。

Warm Regards,
J.

原文地址:http://www.junchenwu.com/2005/01/sp2flashjs_1.html