0

I'm including a funky script (from the german social network VZ) in my page which requires me to insert a script block containing a custom "language":

<script type="vz/login">
    client_id : c47a1d7f134b88c9f12448e08f2ef7289e9fc8
    redirect_uri : http://game.example.com/vzcallback.html
    callback : logResponse
    fields : emails,gender,birthday
</script>

Can I insert such a block into my page at runtime using Javascript (no PHP or other server-side code)? I need this to set client_id dynamically.

Additionally I also need to insert something like:

<script src="https://secure.studivz.net/Js/id/v4/library.js" 
    data-authority="platform-redirect.vz-modules.net/r"
    data-authorityssl="platform-redirect.vz-modules.net/r" type="text/javascript">
</script>

But I don't think adding those data-attributes will be a hard challenge.

2 Answers 2

1

Yes you can,

var el = document.createElement("script");
el.setAttribute("type","vz/login");
el.innerHTML = "client_id : "+new_client_id
               +"\nredirect_uri : http://game.example.com/vzcallback.html"
               +"\ncallback : logResponse"
               +"\nfields : emails,gender,birthday";
document.body.appendChild(el);

For the second snipped use

var headID = document.getElementsByTagName("head")[0];         
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'https://secure.studivz.net/Js/id/v4/library.js';
newScript.setAttribute("data-authority","platform-redirect.vz-modules.net/r");
newScript.setAttribute("data-authorityssl", "platform-redirect.vz-modules.net/r");
headID.appendChild(newScript);
Sign up to request clarification or add additional context in comments.

Comments

0

You can add the vz/login script node to the dom at runtime. But you need to ensure that the vz/login node has been added before the JS that is looking for it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.