Add script to element

Add script to element

  

Hi.

I'm creating a web app integrated with Yammer. I'm unable to add the following script to the head element:

<script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>

I tried using the AddJavascriptTag in HHTPRequestHandler where I assigned the URL as:

"""https://c64.assets-yammer.com/assets/platform_js_sdk.js"" data-app-id=YOUR-APP-CLIENT-ID"

But this is not working on. On inspecting in Chrome, the script tag appears as follows:

<script type="text/javascript" src="" https:="" c64.assets-yammer.com="" assets="" platform_js_sdk.js"="" data-app-id="wZuyoeLNhd1SR6pF5faXUg""></script>

How else do I achieve this?

I've also tried retrieving the head ID using getElementByID. That also doesn't seem to be working.

Hi,

You can try this using an expression:

SyntaxEditor Code Snippet

"<script>
    document.write('<script type=""text/javascript"" src=""https://c64.assets-yammer.com/assets/platform_js_sdk.js"" data-app-id=""your-app-id""><\/script>');
</script>"


Please be aware your data-app-id is in your question.

I think you can create a js script as resource file and include this one through HTTPRequestHandler AddJavascriptTag


Good luck

Hi Barong,


How do you get the 

data-app-id="your-app-id">

part in the script tag in your solution?

hi Johan,

i tried like this in the JavaScript property of the screen:

SyntaxEditor Code Snippet

var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "http://c64.assets-yammer.com/assets/platform_js_sdk.js";
    jQuery.data(s, "data_app_id", "YOUR-APP-CLIENT-ID" );
    // Use any selector
     alert("here==" + jQuery.data( s, "data_app_id" ));
    $("head").append(s);

however, i am fail if using https, instead of http for the src.

and i cannot alert the result in a button, but it works above..alert...here, always undefined:

SyntaxEditor Code Snippet (not work in button - RunJavascript... httprequesthandler...)

var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "http://c64.assets-yammer.com/assets/platform_js_sdk.js";
    jQuery.data(s, "data_app_id", "YOUR-APP-CLIENT-ID" );
    // Use any selector
     //alert("here==" + jQuery.data( s, "data_app_id" ));
    $("head").append(s);

regards,

bb

You should get ride of the http:// I think just do:

s.src = "//c64.assets-yammer.com/assets/platform_js_sdk.js";


If you application is on http it will use http. is you application on https if will be on https too.

Let me know if it works.