Главная > Javascript > javascript: изменить wmode

javascript: изменить wmode

function fix_flash() {
	var embeds = document.getElementsByTagName('embed');
	for(i=0; i<embeds.length; i++)  {
		embed = embeds[i];
		var new_embed;
		if(embed.outerHTML) {
			var html = embed.outerHTML;
			if(html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
			new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i,"wmode='transparent'");
			else 
			new_embed = html.replace(/<embed\s/i,"<embed wmode='transparent' ");
			embed.insertAdjacentHTML('beforeBegin',new_embed);
			embed.parentNode.removeChild(embed);
		} else {
			new_embed = embed.cloneNode(true);
			if(!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase()=='window')
			new_embed.setAttribute('wmode','transparent');
			embed.parentNode.replaceChild(new_embed,embed);
		}
	}
	var objects = document.getElementsByTagName('object');
	for(i=0; i<objects.length; i++) {
		object = objects[i];
		var new_object;
		if(object.outerHTML) {
			var html = object.outerHTML;
			if(html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
			new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i,"<param name='wmode' value='transparent' />");
			else 
			new_object = html.replace(/<\/object\>/i,"<param name='wmode' value='transparent' />\n</object>");
			var children = object.childNodes;
			for(j=0; j<children.length; j++) {
				if(children[j].getAttribute('name').match(/flashvars/i)) {
					new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i,"<param name='flashvars' value='"+children[j].getAttribute('value')+"' />");
				}
			}
			object.insertAdjacentHTML('beforeBegin',new_object);
			object.parentNode.removeChild(object);
		}
	}
}
$(document).ready(function () {
	fix_flash();    
});

http://www.developersnippets.com/2010/12/04/how-to-add-wmodetransparent-for-flash-object-using-jquery-and-native-javascript/
http://www.onlineaspect.com/2009/08/13/javascript_to_fix_wmode_parameters/

Categories: Javascript Tags:
  1. Пока что нет комментариев.
Похожие публикации