swfupload init 和 addOnloadEvent

发布于 2024-10-08 02:29:02 字数 1269 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花期渐远 2024-10-15 02:29:02

您需要首先在函数外部定义 swfu 对象以使其全局。

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;
  }

}

var swf;

function initSwfUpload()
{
         swf = new SWFUpload({
                                // Backend Settings
                                upload_url: "../../../upload.php",
                                ...
                                ....
        })

}

然后你就可以使用这个了。

<script type="text/javascript">
        addOnloadEvent(initSwfUpload);
        swf.addPostParam('c','1');
</script>

You need to define swfu object outside function first to make it global.

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;
  }

}

var swf;

function initSwfUpload()
{
         swf = new SWFUpload({
                                // Backend Settings
                                upload_url: "../../../upload.php",
                                ...
                                ....
        })

}

Then you can use this.

<script type="text/javascript">
        addOnloadEvent(initSwfUpload);
        swf.addPostParam('c','1');
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文