javascript - 如何从父窗口中的 iframe(Sharepoint 托管应用程序,(应用程序部分)))打开模式对话框弹出窗口

标签 javascript jquery html sharepoint iframe

所以我开发了这个共享点托管应用程序,其中包含一个呈现日历的应用程序部分,当他们点击某一天时,它必须打开一个模式弹出窗口,其中包含我已有的 url。

我会把错误贴在最后。

<script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>

<!-- Core CSS File. The CSS code needed to make eventCalendar works -->
<link rel="stylesheet" href="../Content/eventCalendar.css">

<!-- Theme CSS file: it makes eventCalendar nicer -->
<link rel="stylesheet" href="../Content/eventCalendar_theme_responsive.css">

这是JS

var SPHostUrl;
var SPAppWebUrl;
var ListaEventos;
var Categoria;
var ready = false;
var $events = [];

// this function is executed when the page has finished loading. It performs two tasks:
//    1. It extracts the parameters from the url
//    2. It loads the request executor script from the host web
$(document).ready(function () {
    var params = document.URL.split("?")[1].split("&");
    for (var i = 0; i < params.length; i = i + 1) {
        var param = params[i].split("=");
        switch (param[0]) {
            case "SPAppWebUrl":
                SPAppWebUrl = decodeURIComponent(param[1]);
                break;
            case "SPHostUrl":
                SPHostUrl = decodeURIComponent(param[1]);
                break;
            case "TituloListaEventos":
                TituloListaEventos = decodeURIComponent(param[1]);
                break;
            case "Categoria":
                Categoria = decodeURIComponent(param[1]);
                break;
            case "NombreListaEventos":
                NombreListaEventos = decodeURIComponent(param[1]);
                break;
        }
    }

    // load the executor script, once completed set the ready variable to true so that
    // we can easily identify if the script has been loaded
    $.getScript(SPHostUrl + "/_Layouts/15/SP.RequestExecutor.js", function (data) {
        ready = true;
        getItems();
        ShowServerInformation();
    });


    var sub = SPHostUrl.substring(0, SPHostUrl.lastIndexOf('/'))
    $('head').append('<link rel="stylesheet" href="' + sub + '/Style%20Library/SPCCapatech/SPCCapatech.css">');
    $('head').append('<link rel="stylesheet" href="' + sub + '/Style%20Library/SPCCapatech/colors.css">');
});

function ShowServerInformation() {

    var options = {
        url: "/_layouts/Viewlsts.aspx&IsDlg=1",
        tite: 'Server Information',
        allowMaximize: false,
        showClose: true,
        width: 430,
        height: 230
    };
    parent.SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
    return false;

}

执行 showserverinformation 函数时出现此错误:

 Permission denied to access property "SP"

最佳答案

这是标准的安全限制。否则,任何 IFRAME JavaScript 都可以在父窗口中执行任何它想执行的操作。

为了操作父窗口你必须使用HTML 5 Messaging API :

  1. 从您的 IFRAME 执行 window.postMessage() 以向父窗口发送“订单”。
  2. 在父窗口中处理此消息并创建模态窗口作为对此消息的 react 。

关于javascript - 如何从父窗口中的 iframe(Sharepoint 托管应用程序,(应用程序部分)))打开模式对话框弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30378426/

相关文章:

javascript - 为什么 date.valueOf() == date 会导致 false?

Javascript不捕获?

jquery - 更改类函数

jquery - 我可以更改 JQuery 验证器方法的文本颜色吗?

css - 如何减少div中两个标签之间的空间

javascript - Angularjs复选框过滤器,如何做重置按钮?

javascript - 在谷歌地图上添加多个标记变得越来越长

jquery on 与 click 方法

javascript - 如何在动态位置显示 jqueryUI

android - 移动 Chrome 和高度相关的大小调整和滚动