swfupload init 和 addOnloadEvent
我正在使用 addOnloadEvent(initSwfUpload) 函数来初始化 swf上传。
这是我的函数
function addOnloadEvent(fnc){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", fnc, false );
else if ( typeof window.attachEvent != "undefined" ) {
window.attachEvent( "onload", fnc );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
window[fnc]();
};
}
else
window.onload = fnc;
}
}
function initSwfUpload()
{
var swf = new SWFUpload({
// Backend Settings
upload_url: "../../../upload.php",
...
....
})
}
它工作正常,但现在我需要使用 addPostParam(name, value) 但 swf 不可用。
代码
<script type="text/javascript">
addOnloadEvent(initSwfUpload);
swf.addPostParam('c','1');
</script>
这是我收到消息 swf 未定义的
。可以使用 addOnloadEvent 方法来实现上述目的。
由于多种原因,我不想使用经典的 swfupload init
var swfu;
window.onload = function () {
swfu = new SWFUpload({
.......
谢谢
i am using an addOnloadEvent(initSwfUpload) function to init the
swfupload.
Here are my functions
function addOnloadEvent(fnc){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", fnc, false );
else if ( typeof window.attachEvent != "undefined" ) {
window.attachEvent( "onload", fnc );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
window[fnc]();
};
}
else
window.onload = fnc;
}
}
function initSwfUpload()
{
var swf = new SWFUpload({
// Backend Settings
upload_url: "../../../upload.php",
...
....
})
}
Its working fine but now i need to use the addPostParam(name, value)
but swf is not available.
Here is the code
<script type="text/javascript">
addOnloadEvent(initSwfUpload);
swf.addPostParam('c','1');
</script>
I get the message swf is undefined.
Is possible using the addOnloadEvent approach to achieve the above.
For several reasons i dont want ro use the classic swfupload init
var swfu;
window.onload = function () {
swfu = new SWFUpload({
.......
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要首先在函数外部定义 swfu 对象以使其全局。
然后你就可以使用这个了。
You need to define swfu object outside function first to make it global.
Then you can use this.