Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

internet explorer - Working with "Out" Parameters in JavaScript

I am working with an ActiveX control in Internet Explorer 8 that is to display a save file dialog which let's the user choose a file name and file type (jpg, gif, etc). These values get passed to code and then are used in a different method to save the file. Unfortunately the method that invokes the dialog has no return value, and the file name and file type are passed in as out parameters.

The signature of the method (expressed in Visual Basic) looks like this:

Public Sub SaveFileDialog( _
   ByVal bstrDialogType As Variant, _
   ByRef pbstrFileName As String, _
   ByRef out_pvType As Long _
)

The two ByRef parameters are the out parameters.

I have written the following JavaScript code:

try
{
    var saveFileName, saveFileType; // out variables
    gxVideoPlayBack.SaveFileDialog("image", saveFileName, saveFileType);
    alert(saveFileName); // displays "undefined"
    alert(saveFileType); // displays "undefined"
}
catch(error)
{
    if(!error.number === -2147221484) // User clicked cancel.
    {  
        alert(error.message);
    }
}

The code works in that the ActiveX control produces its dialog, and I can handle error conditions, but I can't seem to figure out how to capture the values of the out parameters.

In the code gxVideoPlayBack is a reference to the ActiveX control embedded in the DOM via an HTML element.

If JavaScript will not work for this, can it be done in VBScript?

As an alternative I can just implement my own dialog, but would rather use the one provided.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Edit: It seems that it's not possible to have "out" parameters in JavaScript/JScript.

Original: Perhaps the approach described in this article will work:

var saveFileName={}, saveFileType={}; // Empty "output" objects.
gxVideoPlayBack.SaveFileDialog("image", saveFileName, saveFileType);
alert(saveFileName.value); // The "value" attribute is assigned ...
alert(saveFileType.value); // ... by the "SaveFileDialog" method?

I suppose the idea is that the WSH wrapper for this native call will attempt to assign the "value" property of the given output parameters, so you can either override the value setter or just give it an object with a built-in value setter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...