none
object undefined error in task panel app for office RRS feed

  • Question

  • hi there,

       I've a html page with a baidu map control in it, it works all right with a single html page:

    <html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>百度地图API地点搜索-获取经纬度DEMO</title>
        <meta name="description" content="Assyria Map App">
        <meta name="keywords" content="Assyria Map App">
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
    
    
        <meta name="GENERATOR" content="MSHTML 9.00.8112.16526">
    
    </head>
    <body>
        <form method="get" action="">
            <label>地点:</label><input id="where" name="where"
                                     type="text"><input onclick="sear(document.getElementById('where').value);" value="地图上找" type="button"><br>
            <div style="border: 1px solid gray; width: 520px; height: 340px;"
                 id="container"></div><br>经纬度:  <input id="lonlat" name="lonlat" type="text">
        </form>
        <script type="text/javascript">
            var map = new BMap.Map("container");//在指定的容器内创建地图实例
            map.setDefaultCursor("crosshair");//设置地图默认的鼠标指针样式
            map.enableScrollWheelZoom();//启用滚轮放大缩小,默认禁用。
            map.centerAndZoom(new BMap.Point(116.124878, 24.309178), 20);
            map.addControl(new BMap.NavigationControl());
            map.addEventListener("click", function (e) {//地图单击事件
                document.getElementById("lonlat").value = e.point.lng + ", " + e.point.lat;
            });
            var myCity = new BMap.LocalCity();
            //myCity.get(iploac);
            function sear(result) {//地图搜索
                var local = new BMap.LocalSearch(map, {
                    renderOptions: { map: map }
                });
                local.search(result);
            }
        </script>
    
    
    </body>
    
    </html>
    

    but when I put them into my home.html in my app for office I got an error of "BMap" undefined. here's the Home.html:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>百度地图API地点搜索-获取经纬度DEMO</title>
        <meta name="description" content="Assyria Map App">
        <meta name="keywords" content="Assyria Map App">
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
    
    
        <meta name="GENERATOR" content="MSHTML 9.00.8112.16526">
        <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
        <link href="../../Content/Office.css" rel="stylesheet" type="text/css" />
        <script src="https://appsforoffice.microsoft.com/lib/1.0/hosted/office.js" type="text/javascript"></script>
    
        <!-- To enable offline debugging using a local reference to Office.js, use:                        -->
        <!--    <script src="../../Scripts/Office/MicrosoftAjax.js" type="text/javascript"></script>       -->
        <!--    <script src="../../Scripts/Office/1.0/office.js" type="text/javascript"></script>          -->
    
        <link href="../App.css" rel="stylesheet" type="text/css" />
        <script src="../App.js" type="text/javascript"></script>
    
        <link href="Home.css" rel="stylesheet" type="text/css" />
        <script src="Home.js" type="text/javascript"></script>
    </head>
    <body>
        <!-- Page content -->
        <div id="content-header">
            <div class="padding">
                <h1>Welcome</h1>
            </div>
        </div>
        <form method="get" action="">
            <label>地点:</label><input id="where" name="where"
                                     type="text"><input onclick="sear(document.getElementById('where').value);" value="地图上找" type="button"><br>
            <div style="border: 1px solid gray; width: 520px; height: 340px;"
                 id="container"></div><br>经纬度:  <input id="lonlat" name="lonlat" type="text">
        </form>
    
    </body>
    
    </html>
    

    and home.js:

    /// <reference path="../App.js" />
    
    (function () {
        "use strict";
    
        // The initialize function must be run each time a new page is loaded
        Office.initialize = function (reason) {
            $(document).ready(function () {
                app.initialize();
    
                $('#get-data-from-selection').click(getDataFromSelection);
            });
        };
    
        var map = new BMap.Map("container");
        map.setDefaultCursor("crosshair");
        map.enableScrollWheelZoom();
        map.centerAndZoom(new BMap.Point(116.124878, 24.309178), 20);
        map.addControl(new BMap.NavigationControl());
        map.addEventListener("click", function (e) {
            document.getElementById("lonlat").value = e.point.lng + ", " + e.point.lat;
        });
        var myCity = new BMap.LocalCity();
        //myCity.get(iploac);
        function sear(result) {
            var local = new BMap.LocalSearch(map, {
                renderOptions: { map: map }
            });
            local.search(result);
        }
    
        // Reads data from current document selection and displays a notification
        function getDataFromSelection() {
            Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
                function (result) {
                    if (result.status === Office.AsyncResultStatus.Succeeded) {
                        app.showNotification('The selected text is:', '"' + result.value + '"');
                    } else {
                        app.showNotification('Error:', result.error.message);
                    }
                }
            );
        }
    
    })();

    Hope someone could tell me how to fix that. Thanks.

    -Regards,

    Aaron


    jun

    Wednesday, January 1, 2014 6:11 AM

Answers

  • Hi Aaron,

    >>Is there any other way besides pop-up windows? Can an iframe or content panel work with a ActiveX control in that?<<
    No, we can't use ActiveX controls in the apps for Office.

    >>I found the we've a app for office called "Bing map app" which is also a content panel map. Does it use activeX?<<
    As far as I know, it doesn't use activeX controls.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 8, 2014 11:00 AM
    Moderator

All replies

  • Hi Aaron,

    I found you used ActiveX in your code when I tested it in a single web page.

    We may not use ActiveX control in an app for Office. If you want to integrate functionality specific to Windows, for example, gaining access to a microphone or downloading a file, you can do this in a pop-out browser window.

    More information please see FAQ below:
    FAQ for developing apps for Office-Can I use ActiveX controls in an app for Office

    Best regards
    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 2, 2014 5:23 AM
    Moderator
  • Hi Fei,

       Thanks for your reply. Is there any other way besides pop-up windows? Can an iframe or content panel work with a ActiveX control in that?

    I found the we've a app for office called "Bing map app" which is also a content panel map. Does it use activeX?

    -Thanks,

    Aaron


    jun

    Tuesday, January 7, 2014 7:33 AM
  • Hi Aaron,

    >>Is there any other way besides pop-up windows? Can an iframe or content panel work with a ActiveX control in that?<<
    No, we can't use ActiveX controls in the apps for Office.

    >>I found the we've a app for office called "Bing map app" which is also a content panel map. Does it use activeX?<<
    As far as I know, it doesn't use activeX controls.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 8, 2014 11:00 AM
    Moderator