31
去掉Flash边框线-代码
在网上找了很多次有关去掉FLASH边框线的技术文章,刚才将这个效果应用到自己网站,发现果然可以彻底实现,呵呵:
方法一:加载flash.js,这个方法仅使用一般FLAH单独加载:
<head>与</head>之间添加:
<script language=”javascript” type=”text/javascript” src=”/js/flash.js”></script>
flash.js 代码如下:
//代码开始
function writeflashhtml( arg )
{
var parm = []
var _default_version = “8,0,24,0″;
var _default_quality = “high”;
var _default_align = “middle”;
var _default_menu = “false”;
for(i = 0; i < arguments.length; i ++)
{
parm[i] = arguments[i].split(’ ‘).join(”).split(’=')
for (var j = parm[i].length-1; j > 1; j –){
parm[i][j-1]+=”=”+parm[i].pop();
}
switch (parm[i][0])
{
case ‘_version’ : var _version = parm[i][1] ; break ;
case ‘_swf’ : var _swf = parm[i][1] ; break ;
case ‘_base’ : var _base = parm[i][1] ; break ;
case ‘_quality’ : var _quality = parm[i][1] ; break ;
case ‘_loop’ : var _loop = parm[i][1] ; break ;
case ‘_bgcolor’ : var _bgcolor = parm[i][1] ; break ;
case ‘_wmode’ : var _wmode = parm[i][1] ; break ;
case ‘_play’ : var _play = parm[i][1] ; break ;
case ‘_menu’ : var _menu = parm[i][1] ; break ;
case ‘_scale’ : var _scale = parm[i][1] ; break ;
case ‘_salign’ : var _salign = parm[i][1] ; break ;
case ‘_height’ : var _height = parm[i][1] ; break ;
case ‘_width’ : var _width = parm[i][1] ; break ;
case ‘_hspace’ : var _hspace = parm[i][1] ; break ;
case ‘_vspace’ : var _vspace = parm[i][1] ; break ;
case ‘_align’ : var _align = parm[i][1] ; break ;
case ‘_class’ : var _class = parm[i][1] ; break ;
case ‘_id’ : var _id = parm[i][1] ; break ;
case ‘_name’ : var _name = parm[i][1] ; break ;
case ‘_style’ : var _style = parm[i][1] ; break ;
case ‘_declare’ : var _declare = parm[i][1] ; break ;
case ‘_flashvars’ : var _flashvars = parm[i][1] ; break ;
default :;
}
}
var thtml = “”
thtml += “<object classid=’clsid:d27cdb6e-ae6d-11cf-96b8-444553540000′ codebase=’http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=” + ((_version)?_version:_default_version) + “‘”
if(_width) thtml += ” width=’” + _width + “‘”
if(_height) thtml += ” height=’” + _height + “‘”
if(_hspace) thtml += ” hspace=’” + _hspace + “‘”
if(_vspace) thtml += ” vspace=’” + _vspace + “‘”
if(_align) thtml += ” align=’” + _align + “‘”
else thtml += ” align=’” + _default_align + “‘”
if(_class) thtml += ” class=’” + _class + “‘”
if(_id) thtml += ” id=’” + _id + “‘”
if(_name) thtml += ” name=’” + _name + “‘”
if(_style) thtml += ” style=’” + _style + “‘”
if(_declare) thtml += ” ” + _declare
thtml += “>”
if(_swf) thtml += “<param name=’movie’ value=’” + _swf + “‘>”
if(_quality) thtml += “<param name=’quality’ value=’” + _quality + “‘>”
else thtml += “<param name=’quality’ value =’” + _default_quality + “‘>”
if(_loop) thtml += “<param name=’loop’ value=’” + _loop + “‘>”
if(_bgcolor) thtml += “<param name=’bgcolor’ value=’” + _bgcolor + “‘>”
if(_play) thtml += “<param name=’play’ value=’” + _play + “‘>”
if(_menu) thtml += “<param name=’menu’ value=’” + _menu + “‘>”
else thtml += “<param name=’menu’ value=’” + _default_menu + “‘>”
if(_scale) thtml += “<param name=’scale’ value=’” + _scale + “‘>”
if(_salign) thtml += “<param name=’salign’ value=’” + _salign + “‘>”
if(_wmode) thtml += “<param name=’wmode’ value=’” + _wmode + “‘>”
if(_base) thtml += “<param name=’base’ value=’” + _base + “‘>”
if(_flashvars) thtml += “<param name=’flashvars’ value=’” + _flashvars + “‘>”
thtml += “<embed pluginspage=’http://www.macromedia.com/go/getflashplayer’”
if(_width) thtml += ” width=’” + _width + “‘”
if(_height) thtml += ” height=’” + _height + “‘”
if(_hspace) thtml += ” hspace=’” + _hspace + “‘”
if(_vspace) thtml += ” vspace=’” + _vspace + “‘”
if(_align) thtml += ” align=’” + _align + “‘”
else thtml += ” align=’” + _default_align + “‘”
if(_class) thtml += ” class=’” + _class + “‘”
if(_id) thtml += ” id=’” + _id + “‘”
if(_name) thtml += ” name=’” + _name + “‘”
if(_style) thtml += ” style=’” + _style + “‘”
thtml += ” type=’application/x-shockwave-flash’”
if(_declare) thtml += ” ” + _declare
if(_swf) thtml += ” src=’” + _swf + “‘”
if(_quality) thtml += ” quality=’” + _quality + “‘”
else thtml += ” quality=’” + _default_quality + “‘”
if(_loop) thtml += ” loop=’” + _loop + “‘”
if(_bgcolor) thtml += ” bgcolor=’” + _bgcolor + “‘”
if(_play) thtml += ” play=’” + _play + “‘”
if(_menu) thtml += ” menu=’” + _menu + “‘”
else thtml += ” menu=’” + _default_menu + “‘”
if(_scale) thtml += ” scale=’” + _scale + “‘”
if(_salign) thtml += ” salign=’” + _salign + “‘”
if(_wmode) thtml += ” wmode=’” + _wmode + “‘”
if(_base) thtml += ” base=’” + _base + “‘”
if(_flashvars) thtml += ” flashvars=’” + _flashvars + “‘”
thtml += “></embed>”
thtml += “</object>”
document.write(thtml)
}
//代码结束
然后在需要加载网页的地方添加JS,相关参数自由修改:
<script language=”javascript” type=”text/javascript”>
writeflashhtml(”_swf=/images/banner.swf”, “_width=542px”, “_height=176px” ,”_wmode=transparent”);
</script>
方法二:适用于对SWF文件添加了修改调用参数,如DEDECMS幻灯片调用,这个方法能做到彻底去除FLASH边框线:
在<head>与</head>之间添加代码:
<script type=”text/javascript” src=”/js/objectSwap.js”></script>
objectswap.js代码如下:
/* ObjectSwap – Bypasses the new ActiveX Activation requirement in Internet Explorer by swapping existing ActiveX objects on the page with the same objects. Can also be used for Flash version detection by adding the param:
<param name=”flashVersion” value=”8″ /> to the object tag.
Author: Karina Steffens, www.neo-archaic.net
Created: April 2006
Changes and bug fixes: May 2006
Bug fixes: June 2006
Changes: October 2006 (Included Opera9 and excluded IE5.5)
*/
//Check if the browser is InternetExplorer, and if it supports the getElementById DOM method
var ie = (document.defaultCharset && document.getElementById && !window.home);
var opera9 = false;
if (ie){
//Check for ie 5.5 and exclude it from the script
var ver=navigator.appVersion.split(”MSIE”)
ver=parseFloat(ver[1])
ie = (ver >=6)
}else if (navigator.userAgent.indexOf(”Opera”)!=-1) {
//Check for Opera9 and include it in the ObjectSwap
var versionindex=navigator.userAgent.indexOf(”Opera”)+6
if (parseInt(navigator.userAgent.charAt(versionindex))>=9)
opera9 = true;
}
//Perform ObjectSwap if the browser is IE or Opera (if not just check flashVersion)
var oswap = (ie || opera9)
//Hide the object to prevent it from loading twice
if (oswap){
document.write (”<style id=’hideObject’> object{display:none;} </style>”);
}
/*Replace all flash objects on the page with the same flash object,
by rewriting the outerHTML values
This bypasses the new IE ActiveX object activation issue*/
objectSwap = function(){
if (!document.getElementsByTagName){
return;
}
//An array of ids for flash detection
var stripQueue = [];
//Get a list of all ActiveX objects
var objects = document.getElementsByTagName(’object’);
for (var i=0; i<objects.length; i++){
var o = objects[i];
var h = o.outerHTML;
//The outer html omits the param tags, so we must retrieve and insert these separately
var params = “”;
var hasFlash = true;
for (var j = 0; j<o.childNodes.length; j++) {
var p = o.childNodes[j];
if (p.tagName == “PARAM”){
//Check for version first – applies to all browsers
//For this to work, a new param needs to be included in the object with the name “flashVersion” eg:
//<param name=”flashVersion” value=”7″ />
if (p.name == “flashVersion”){
hasFlash = detectFlash(p.value);
if (!hasFlash){
//Add the objects id to the list (create a new id if there’s isn’t one already)
o.id = (o.id == “”) ? (”stripFlash”+i) : o.id;
stripQueue.push(o.id);
break;
}
}
params += p.outerHTML;
}
}
if (!hasFlash){
continue;
}
//Only target internet explorer
if (!oswap){
continue;
}
//Avoid specified objects, marked with a “noswap” classname
if (o.className.toLowerCase().indexOf (”noswap”) != -1){
continue;
}
//Get the tag and attributes part of the outer html of the object
var tag = h.split(”>”)[0] + “>”;
//Add up the various bits that comprise the object:
//The tag with the attributes, the params and it’s inner html
var newObject = tag + params + o.innerHTML + ” </OBJECT>”;
//And rewrite the outer html of the tag
o.outerHTML = newObject;
}
//Strip flash objects
if (stripQueue.length) {
stripFlash(stripQueue)
}
//Make the objects visible again
if (oswap){
document.getElementById(”hideObject”).disabled = true;
}
}
detectFlash = function(version){
if(navigator.plugins && navigator.plugins.length){
//Non-IE flash detection.
var plugin = navigator.plugins["Shockwave Flash"];
if (plugin == undefined){
return false;
}
var ver = navigator.plugins["Shockwave Flash"].description.split(” “)[2];
return (Number(ver) >= Number(version))
} else if (ie && typeof (ActiveXObject) == “function”){
//IE flash detection.
try{
var flash = new ActiveXObject(”ShockwaveFlash.ShockwaveFlash.” + version);
return true;
}
catch(e){
return false;
}
}
//Catchall – skip detection
return true;
}
//Loop through an array of ids to strip
//Replace the object by a div tag containing the same innerHTML.
//To display an alternative image, message for the user or a link to the flash installation page, place it inside the object tag.
//For the usual object/embed pairs it needs to be enclosed in comments to hide from gecko based browsers.
stripFlash = function (stripQueue){
if (!document.createElement){
return;
}
for (var i=0; i<stripQueue.length; i++){
var o = document.getElementById(stripQueue[i]);
var newHTML = o.innerHTML;
//Strip the comments
newHTML = newHTML.replace(/<!–s/g, “”);
newHTML = newHTML.replace(/s–>/g, “”);
//Neutralise the embed tag
newHTML = newHTML.replace(/<embed/gi, “<span”);
//Create a new div element with properties from the object
var d = document.createElement(”div”);
d.innerHTML = newHTML;
d.className = o.className;
d.id = o.id;
//And swap the object with the new div
o.parentNode.replaceChild(d, o);
}
}
//Initiate the function without conflicting with the window.onload event of any preceding scripts
var tempFunc = window.onload;
window.onload = function(){
if (typeof (tempFunc) == “function”){
try{
tempFunc();
} catch(e){}
}
objectSwap();