1

I am trying to add a github gist to my webpage on the click of a button however the gist is not appearing.

function createGist(gistId = "bd10e846c6eae4419c3041f3da1b82a0"){
    var script = document.createElement("script");
    script.src = "https://gist.github.com/snakifyanswers/" + gistId + ".js";
    document.body.appendChild(script)    }

I am left with nothing there even though in inspect element I can see the script object.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • 2
    Being able to see it in the inspector sort of implies it's there; what do you mean by "not appearing"? – Dave Newton Nov 24 '21 at 17:35
  • It is there however when I add `` to my html file it displays the gist I want to show however the scr script is not running when I add the element via javascript. – Nicknotnam e Nov 24 '21 at 17:40
  • It doesn't work because the script uses `document.write`. Have a [look at this](https://stackoverflow.com/questions/24297829/execute-write-on-doc-it-isnt-possible-to-write-into-a-document-from-an-asynchr) – Đinh Carabus Nov 24 '21 at 17:44
  • How do you know it isn't running? – Dave Newton Nov 24 '21 at 17:50
  • Using postscribe I have got the gist to appear. – Nicknotnam e Nov 24 '21 at 18:46
  • 1
    Please self-answer the question with your solution (and perhaps edit the question to include more details). On SO we don't mark titles with tags; we mark an answer as accepted. – Dave Newton Nov 24 '21 at 18:49

0 Answers0