开发者

A JavaScript problem by a beginner

Good day, I've been searching Google on a lot of issues I have and I always find the answers here and I'm hoping that someone would give time answering this stupid question. I'm a beginner in JavaScript and I happened to be creating a personal site that uses Flexpaper as the viewer for some of my files, and I'm just wondrin' how I can change the URL based on href that the users will click on. Here's the Flexpaper snippet:

        var swfVersionStr = "10.0.0";
        var xiSwfUrlStr = "playerProductInstall.swf";
        var file = "1984.swf";
        var flashvars = { 
              SwfFile : escape(file),
              Parameters here
              };

         var params = {

            }
        Parameters and Attributes here
        swfobject.embedSWF(
            "FlexPaperViewer.swf", "flashContent", 
            "700", "550",
            swfVersionStr, xiSwfUrlStr, 
            flashvars, params, attributes);
        swfobject.createCSS("#flashContent", "display:block;text-align:left;");`

I'm planning to put the viewer on iframe or just on the side, and then the links on the other side or frame.

<a href="books/google search APIs.swf">Google sear开发者_C百科ch APIs</a>

It should change the variable file on the code. I'm hoping you could help me out.


Try defining the following javascript function (which named swapSwf):

function swapSwf(swfPath) {
    swfobject.embedSWF(swfPath, "flashContent", "700", "550");
}

And the just use it in the link with the proper javascript: prefix:

<a href="javascript:swapSwf('books/google search APIs.swf')">Google search APIs</a>


First, use a function to create the SWF, that way you can pass in separate parameters for different files.

Second, in the anchor tag, return false at the end of your function, while also "return false" is used in the onClick event handler within the anchor tag. This will cancel following the link within the browser, and allow the function to do it's business (changing the FlexPaper document).

<a href="books/google search APIs.swf" onClick="return showFile(this.href);">Google search APIs</a>

(I haven't checked the following, so you will have to test)

Then, the showFile function with the location of the swfFile is passed in as a parameter:

function showFile (swfFile) {
    var swfVersionStr = "10.0.0";
    var xiSwfUrlStr = "playerProductInstall.swf";
    var flashvars = { 
            SwfFile : escape(swfFile),
            Scale : 0.95, 
            ZoomTransition : "easeOut",
            ZoomTime : 0.5,
            ZoomInterval : 0.2,
            FitPageOnLoad : false,
            FitWidthOnLoad : false,
            PrintEnabled : true,
            FullScreenAsMaxWindow : false,
            ProgressiveLoading : true,
            MinZoomSize : 0.3,
            MaxZoomSize : 5,
            localeChain: "en_US"
        };
    var params = {}
    params.quality = "high";
    params.bgcolor = "#ffffff";
    params.allowscriptaccess = "sameDomain";
    params.allowfullscreen = "true";
    params.wmode = "opaque";
    var attributes = {};
    attributes.id = "FlexPaperViewer";
    attributes.name = "FlexPaperViewer";
    swfobject.embedSWF(
        "/FlexPaperViewer.swf", "flashContent", 
        "800", "550",
        swfVersionStr, xiSwfUrlStr, 
        flashvars, params, attributes
    );
    swfobject.createCSS("#flashContent", "display:block;text-align:left;");
    return false;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜