Jump to content

Problem with initializing IFrame? Newbie question

- - - - -

  • Please log in to reply
2 replies to this topic

#1
alirezan

alirezan

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Hello

I am trying to create a simple simple WYSIWYG editor for my website. I found this really simple code which i really liked but the problem is, I am an absolute beginner in javascript and I don't know how to do simple things. What I want to do is very simple. First of all, here is the code:

Quote

editor.js


var Editor;

function Format(action)
{
Editor.execCommand(action, false, null);
}

function Colour(colour)
{
Editor.execCommand("forecolor",false, colour);
}

window.onload = function()
{
Editor = document.getElementById('textbox').contentWindow.document;
Editor.designMode = "on";
document.forms[0].onsubmit = function()
{
var text = document.getElementById('text');
text.value = Editor.body.innerHTML;
}
}

and

Quote

editor.html

<html>
<head>
<title>Simple Javascript WYSIWYG Editor</title>
<script language="Javascript" src="editor.js"></script>
</head>
<body>
<form method="POST">
<div>
<input type="button" onclick="Colour('Green')" style="background-color:Green;" />
<input type="button" onclick="Colour('Red')" style="background-color:Red;" />
<input type="button" onclick="Colour('Blue')" style="background-color:Blue;" />
<input type="button" onclick="Colour('Black')" style="background-color:Black;" />
<input type="button" onclick="Format('bold')" value="B" />
<input type="button" onclick="Format('italic')" value="I" />
<input type="button" onclick="Format('Underline')" value="U" />
<input type="button" onclick="Format('justifycenter')" value="C" />
<input type="button" onclick="Format('justifyleft')" value="L" />
<input type="button" onclick="Format('justifyright')" value="R" /><br/>
<iframe id="textbox" style="width:300px; height:150px"></iframe><br/>
<input type="submit" value="Go" />
<input type="hidden" id="text" name="text" />
</div>
</form>
</body>
</html>


The code uses an inline frame and all I want to do is to initialize the iframe with a text. For example, I want the Iframe to have "Welcome" text in it when the page loads.
I tried to use insertHTML but it didn't work. Can someone please help me with this?

Thanks

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Simply create a new page that has your welcome message, and start your iframe using that page as the "src"

<iframe id="textbox" style="width:300px; height:150px" src="welcome.html"></iframe>


#3
xx3004

xx3004

    Newbie

  • Members
  • PipPip
  • 13 posts
Actually, you don't need to create a new page [but you can do it anyway].

If you don't want to take more work, add to your window.onload=function(){} these lines:
<script language="javascript" type="text/javascript">
editor=document.getElementById('textbox').contentWindow.document;
editor.designMode="on";
editor.open();
editor.write("<html><head></head><body>WELCOME TO WHATEVER</body></html>");
editor.close();
</script>

Regards,
[x]




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users