0

Question:

I am trying to replace a twitter section on a page with javascript widget for Instagram.

Code:

$('#homepage-social-twitter').replaceWith("<a href='https://instawidget.net/v/user/pfaffmclaren' id='link-37c895c26e36ff'>@pfaffmclaren</a><"+"script src='https://instawidget.net/js/instawidget.js?u=37c895c26e36ff&width=260px'><"+"/script>");

Error:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Chrome Error Details :

instawidget.js?u=37c895c26e36ff&width=260px&_=1535660742861:12 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Any Ideas on how to swap in a script to a web page dynamically as described above ?

Calvin Nunes
  • 6,376
  • 4
  • 20
  • 48
Mike Q
  • 6,716
  • 5
  • 55
  • 62
  • Possible duplicate of [Execute write on doc: It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.](https://stackoverflow.com/questions/24297829/execute-write-on-doc-it-isnt-possible-to-write-into-a-document-from-an-asynchr) – Joseph Cho Aug 30 '18 at 20:58
  • @JosephCho I've already looked at that, and see some critical differences – Mike Q Aug 30 '18 at 21:00
  • Not possible with that script since it seems to use document.write which will overwrite the whole page when used after page is loaded and is why it is being blocked – charlietfl Aug 30 '18 at 21:25
  • Yeah it does ok thanks @charlietfl – Mike Q Aug 30 '18 at 21:33
  • https://jsfiddle.net/s87caz4y/ - not possible with regular way, but you may use "hook". – SpiRT Aug 31 '18 at 01:52

0 Answers0