初学者的 JavaScript 问题

发布于 2024-10-14 17:37:37 字数 963 浏览 1 评论 0原文

美好的一天,我一直在谷歌上搜索我遇到的很多问题,我总是在这里找到答案,我希望有人能花时间回答这个愚蠢的问题。我是 JavaScript 的初学者,我碰巧正在创建一个个人网站,该网站使用 Flexpaper 作为我的一些文件的查看器,我只是想知道如何根据用户将单击的 href 更改 URL 。以下是 Flexpaper 片段:

        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;");`

我计划将查看器放在 iframe 上或仅放在一侧,然后将链接放在另一侧或框架上。

<a href="books/google search APIs.swf">Google search APIs</a>

它应该更改代码上的变量文件。我希望你能帮助我。

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 search APIs</a>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

删除→记忆 2024-10-21 17:37:37

尝试定义以下 javascript 函数(名为 swapSwf):

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

只需在带有正确 javascript: 前缀的链接中使用它即可:

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

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>
泪是无色的血 2024-10-21 17:37:37

首先,使用函数创建 SWF,这样您就可以为不同的文件传递单独的参数。

其次,在锚标记中,在函数末尾返回 false,同时在锚标记内的 onClick 事件处理程序中也使用“return false”。这将取消浏览器中的链接,并允许该功能执行其任务(更改 FlexPaper 文档)。

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

(我没有检查以下内容,因此您必须进行测试)

然后,将带有 swfFile 位置的 showFile 函数作为参数传入:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文