Home  >  Article  >  Web Front-end  >  How to call Flash across domains in JavaScript_javascript skills

How to call Flash across domains in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:40:001122browse

To make a notification sound function for short messages on the page, I originally wanted to use bgsound under Audio IE in HTML5 to implement it, but I found that each browser has different decoding types for Audio, and I suddenly felt like it was crashing. . If you have no other choice, it’s better to use Flash.

I believe that everyone will have some contact with or have heard about the interaction between JavaScript and Flash. In fact, this is also my first time doing this thing. I won’t go into the specific methods, there is a lot of information.

At the beginning, the functions were almost done, and there was no problem in implementation. But at the end, when I put the swf file on the resource service and then called it, something went wrong. I thought it must be another annoying cross-domain problem (CrossDomain). After searching the Internet for a long time, I finally solved the problem.

First of all, to allow your Flash to access the page, you need to add allowscriptaccess=always to the tag.

Secondly, if you want JavaScript in your page to access Flash, you need to add the following content to your Flash script:

Copy code The code is as follows:

import flash.system.Security;
Security.allowDomain('www.jb51.net');

www.jb51.net needs to be replaced with the domain of your own page. If you are not sure, you can use alert(document.domain) to check it. If you need multiple domains to access this Flash, you can add multiple allowDomain records.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn