Hi all of you,
I am new to this group.
Actually i am reading some data from the text and putting it in html file using IFRAME.
Now i want that text to be bold and with customised background color.
Here is the code snippet i am using.
<IFRAME bgcolor="#000000" NAME="ifr_bass" SRC="iframe_bass.txt" WIDTH="96%" HEIGHT="23" FRAMEBORDER="no" SCROLLING="no" MARGINWIDTH="0" MARGINHEIGHT="2" HSPACE="0" VSPACE="0" style="background-color: #000000"></IFRAME>

plz make change in this snippet and provide me with your suggestions ASAP

Thanks in advance

Dani AI

Generated

The iframe is loading a plain text file, so the browser is rendering it as literal text rather than an HTML document that can accept styles. That is the root cause: styling applied in the parent page (or via a simple iframe attribute) cannot change the markup inside a plain-text resource, and scripting or styling the iframe contents is only possible when the framed document is same-origin. See MDN for the iframe element and the same-origin policy for details (iframe (MDN), Same-origin policy (MDN)).

Recommended fixes (ordered by reliability):

  • Serve an actual HTML document as the iframe source. Replace the .txt with a small HTML file that sets background and font weight. Example for the framed file:

    <!doctype html>
    <html>
    <head><meta charset="utf-8"></head>
    <body style="margin:0;background:#000;color:#fff;font-weight:700;">
    The text to display...
    </body>
    </html>
  • If changing filenames is not possible, configure the server to send that file with a text/html MIME type (for Apache, an AddType or ForceType rule). That makes the browser parse it as HTML.

Alternatives when the iframe document is same-origin:

  • Inject styling from the parent via script by accessing the iframe document and setting styles or adding a stylesheet.
  • Skip iframes and fetch the text with JavaScript, then insert it into a styled container (use textContent or wrap in a <pre> and style white-space if preserving line breaks is needed).

Notes tied to earlier replies: suggested tables — that won't affect how a plain-text file is rendered inside an iframe. was right that CSS can do the job, but the CSS must target an HTML document (either the framed page itself or content injected into the parent). Also beware cross-origin restrictions: if the file is served from another domain, parent scripts cannot modify the iframe contents.

Recommended Answers

All 2 Replies

you should try using tables instead of iframes, since they're easier to handle...

HI Navengold
are you opening your html pages in Frame?
as per my understanding i get this.. from your post.
If i am not wrong... then where is the problem?
you can directly put HTML code for getting result or use any css. You can get those from Google search.
Best luck. Good Day

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.