【问题标题】:Serving Static Workspace Files in Oracle APEX with Javascript使用 Javascript 在 Oracle APEX 中提供静态工作区文件
【发布时间】:2021-06-13 05:30:11
【问题描述】:

我正在将 browser notifications 合并到 Oracle APEX 中,但在通知中显示自定义图标时遇到问题。通过提供图像位置的 URL,可以根据自己的喜好调整这些图标。在 Oracle APEX 中,您可以上传静态文件并使用 #WORKSPACE_IMAGES#image.png 引用它们,但是,当我在 JavaScript 中使用它时,#WORKSPACE_IMAGES# 部分不会被替换。 如何在 JavaScript 中获取静态工作区文件(png 图像)的 URL? 我已尝试将以下字符串用于通知的 URL 参数:

showNotification(
    // "https://developers.google.com/web/images/web-fundamentals-icon192x192.png", // Works
    // "r/xxxxx/files/static/v71/image.png",                                        // Works, but is subject to change
    // "#WORKSPACE_IMAGES#image.png",                                               // Does not work
    // "&WORKSPACE_IMAGES.image.png",                                               // Does not work
    // "#IMAGE_PREFIX#image.png",                                                   // Does not work
    // "&IMAGE_PREFIX.image.png",                                                   // Does not work
    notification.title,
    notification.body,
    () => parent.focus()
);

const showNotification = (icon, title, body, onclick) => {
    // Let's check if the browser supports notifications
    if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
    }

    // Let's check whether notification permissions have already been granted
    else if (Notification.permission === "granted") {
        // If it's okay let's create a notification
        let notification = new Notification(title, {
            icon: icon,
            body: body,
        });

        notification.onclick = onclick;
    }

    // Otherwise, we need to ask the user for permission
    else if (Notification.permission !== "denied") {
        Notification.requestPermission();
    }
};

这些工作:

这些不:

  • #WORKSPACE_IMAGES#image.png
  • &WORKSPACE_IMAGES.image.png
  • #IMAGE_PREFIX#image.png
  • &IMAGE_PREFIX.image.png

额外信息

  • 我们在自治数据库上使用 Oracle APEX 20.2

提前致谢!

编辑: 我最终将图像上传到由托管服务提供商处理的域,因此我可以通过该 url 访问图像。

【问题讨论】:

    标签: javascript oracle image url oracle-apex


    【解决方案1】:

    #WORKSPACE_IMAGES#image.png 之类的替换在 Javascript 中应该可以正常工作 - 但前提是该 Javascript 由 APEX 作为页面的一部分呈现,不是如果 Javascript 位于单独的文件中。例如:

    页面运行时:

    【讨论】:

    • 这个答案很有用,我知道它是这样工作的。但是,通知并没有真正呈现在页面上。它由窗口呈现。所以这就是更换不起作用的原因。我最终使用将图像上传到托管域并从那里访问图像。
    • 我知道通知没有呈现在页面上。但是调用警报 的 Javascript 呈现在页面上(在我的回答中使用 APEX 页面 Javascript 时),因此 APEX 在呈现页面之前将 #WORKSPACE_IMAGES# 转换为真实路径。
    猜你喜欢
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 2013-10-17
    • 2011-01-27
    相关资源
    最近更新 更多