0

I am having trouble trying to replace text within a p tag. I've tried a couple ways to get element by id and replace text but no luck. What am I doing wrong?

iframe.html

<div>
    <p id="title">Tom Clancy</p>
</div>

Content.js

var iframe  = document.createElement ('iframe');
iframe.src  = chrome.extension.getURL ('iframe.html');
var topview = document.getElementById('sidebar-content');
topview.parentNode.insertBefore(iframe, topview)

What I Have Tried To Change Text:

iframe.getElementById('title').innerHTML = "Harry Potter";

and

iframe.contentWindow.getElementById('title').innerHTML = "Harry Potter";
  • Have you tried: iframe.contentWindow.document.getElementById('title')? – slacker Dec 05 '20 at 10:08
  • I tried it and it seemed to work but it got blocked by this message. – Hell_ Raisin Dec 05 '20 at 22:19
  • Uncaught SecurityError: Blocked a frame with origin "https://brickseek.com" from accessing a frame with origin "chrome-extension://dk". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "chrome-extension". Protocols must match. – Hell_ Raisin Dec 05 '20 at 22:19
  • 1
    It's a security feature. If you are using this for testing purposes you can disable this feature on your local browser. Here's a really good post on this topic: https://stackoverflow.com/a/25098153 – slacker Dec 07 '20 at 09:52

0 Answers0