0

I want to change content of iframe without src. So i try

var doc = findIframe().get(0).contentWindow.document;
    doc.open();
    doc.write(GM_getResourceText('iframe.html'));
    doc.close();

Where content of iframe.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>iframe</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">some style</style>
        <script> some script</script>
    </head>
<body>
</body>
</html>

But all elemets instead of iframe head appends to iframe body. I execute script from main window. How it can be solved?

Suhan
  • 1,434
  • 2
  • 13
  • 28
  • 1
    When you say "content of iframe" do you mean the current contents before you try and overwrite it, or do you mean the contents of iframe.html? What is findIframe()? When you say "append to body", body of what? The iframe? The containing frame? When are you executing your script and where are you executing it from? Please be clearer. – Jason C Oct 28 '13 at 09:30
  • Possible duplicate of http://stackoverflow.com/questions/11658011/cannot-modify-content-of-iframe-what-is-wrong – william44isme Oct 28 '13 at 09:40
  • Are you sure your code is executing AFTER the DOM has loaded? – Joren Oct 28 '13 at 09:43
  • Might be unrelated to your problem but I don't think you can choose a DOCTYPE with `document.write()`. Apart from that, you suggest you cannot just change the `src` attribute of your ` – Álvaro González Oct 28 '13 at 09:45
  • @Joren Yes, and same origin policy is also not a problem. I just dont understand why i have all elements(script,css) in head but after doc.write they appear in body – Suhan Oct 28 '13 at 09:45
  • @ÁlvaroG.Vicario Try to delete DOCTYPE but it did't help – Suhan Oct 28 '13 at 09:54

0 Answers0