0

I'm creating a custom search result display template. I'd like to reference an EXTERNAL javasacript. The only examples I've seen copy the JS file into a library on the server and reference it from there (i.e.)

$includeScript(this.url, "~sitecollection/Style Library/internalScript.js");

but I would like to do an external script. I've got it working with an external CSS, but it doesn't seem to be working for the script.

</head>
<body>
<script>
    $includeCSS(this.url, "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/10.0.0/css/fabric.min.css");
    $includeScript(this.url, "https://maps.googleapis.com/maps/api/js?key=AKEY&callback=initMap");
</script>

<div id="Control_SearchResults">

doesn't work, and neither does this

</head>
<body>
<script>
    $includeCSS(this.url, "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/10.0.0/css/fabric.min.css");
</script>

<div id="Control_SearchResults">
        <script src='https://maps.googleapis.com/maps/api/js?key=AKEY&callback=initMap'></script>

neither of these solutions appear to load the JavaScript file (using the debugger to see what files have been loaded, and the network tool to see what URLS have been called) and when I attempt to use it to initialize a map tells me "google is not defined"

 map = new google.maps.Map(document.getElementById('map'), { ….

Any thoughts? Or is it a limitation of sharepoint to not load external JS files this way? I really only need this in limited situations so I'd rather not add the reference to a master page or use some kind of global solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.