문제

IS there a clean and concise way to put multiple swfobjects into one page in HTMl, bearing in mind they will all need different flashvars?

Below is just one:

<script type="text/javascript">
            var flashvars = {};
            var params = {};
            var attributes = {};
            swfobject.embedSWF("/swf/AllBookings.swf", "no-flash", "620", "365", "9.0.0", false, flashvars, params, "all_bookings");
</script>

I could copy and paste this a few times and change the names, but there must be a nice way.

도움이 되었습니까?

해결책

Put all relevant parameters into an array and iterate over it:

var swfs = [
    {
        url: '/swf/AllBookings.swf',
        id: 'no-flash',
        width: 620,
        height: 365,
        flashvars: {},
        params: {},
        attributes: {}
    },
    {
        url: '/foo.swf',
        id: 'bar',
        width: 620,
        height: 365,
        flashvars: {},
        params: {},
        attributes: {}
    }
];

for (var i = 0; i < swfs.length; i++) {
    var swf = swfs[i];
    swfobject.embedSWF(
        swf.url, swf.id, swf.width, swf.height, "9.0.0", false, 
        swf.flashvars, swf.params, swf.attributes
    );
};

다른 팁

You only need to copy and paste this part:

swfobject.embedSWF("/swf/AllBookings.swf", "no-flash", "620", "365", "9.0.0", false, flashvars, params, "all_bookings");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top