Jump to content

execCommand and styles


otester

Recommended Posts

  Quote

What have you tried so far, and why does it need to use exec()?

 

Here:

 

<html> 
<head> 
<title></title> 
<script language="JavaScript">

function Init() 

{ 
iView.document.designMode = 'On'; 
}

function bold() 
{ 
iView.document.execCommand('bold', false, null); 
}

function italic() 
{ 
iView.document.execCommand('italic', false, null); 
}

function underline() 
{ 
iView.document.execCommand('underline', false, null); 
}

function font(fontname)
{
iView.document.execCommand(style.font-family:+fontname;, true, null);
}
</script>

<body onLoad="Init()">

<input type="button" onClick="bold()" value="B">
<input type="button" onClick="italic()" value="I">
<input type="button" onClick="underline()" value="U">

<select name="fontChanger" onChange="font(document.quest.fontChanger.value)">
  <option value="Arial">Arial</option>
  <option value="Tahoma">Tahoma</option>
</select>

<br />

<iframe id="iView" style="margin-top: 20px; width: 200px; height:70px"></iframe> 

<br><br>

</body> 

</html>

  Quote

I think it's just .execCommand('fontName', false, null) ..?

 

I tried this but I don't think it's right:

 

<html> 
<head> 
<title></title> 
<script language="JavaScript">

function Init() 

{ 
iView.document.designMode = 'On'; 
}

function bold() 
{ 
iView.document.execCommand('bold', false, null); 
}

function italic() 
{ 
iView.document.execCommand('italic', false, null); 
}

function underline() 
{ 
iView.document.execCommand('underline', false, null); 
}

function font()
{
iView.document.execCommand('fontname', false, null);
}
</script>

<body onLoad="Init()">

<input type="button" onClick="bold()" value="B">
<input type="button" onClick="italic()" value="I">
<input type="button" onClick="underline()" value="U">

<input type="button" onClick="font()" value="Change Font">

<!--<select name="fontname" onChange="font(document.quest.fontChanger.value)">
  <option value="Arial">Arial</option>
  <option value="Tahoma">Tahoma</option>
</select>-->

<br />

<iframe id="iView" style="margin-top: 20px; width: 200px; height:70px"></iframe> 

<br><br>

</body> 

</html>

 

Is there a way your meant to tell it which font?

  Quote

I think you need to uncomment the drop down and pass an actual font name..?

 

This is what I currently have as a test, alert doesn't show :(

 

<html> 
<head> 
<title></title> 
<script language="JavaScript">

function Init() 

{ 
iView.document.designMode = 'On'; 
}

function bold() 
{ 
iView.document.execCommand('bold', false, null); 
}

function italic() 
{ 
iView.document.execCommand('italic', false, null); 
}

function underline() 
{ 
iView.document.execCommand('underline', false, null); 
}

function font(fontname)
{
if(fontname == Arial)
{
	//iView.document.execCommand('fontname', false, fontname);
	alert("Arial!");
}
if(fontname == Tahoma)
{
	//iView.document.execCommand('fontname', false, fontname);
	alert("Arial!");
}
}
</script>

<body onLoad="Init()">

<FORM ACTION="#" NAME="font2">
<input type="button" onClick="bold()" value="B">
<input type="button" onClick="italic()" value="I">
<input type="button" onClick="underline()" value="U">

<select name="fontChanger" onChange="font(document.font2.fontChanger.value)">
  <option value="Arial">Arial</option>
  <option value="Tahoma">Tahoma</option>
</select>
</FORM>
<br />

<iframe id="iView" style="margin-top: 20px; width: 200px; height:70px"></iframe> 

<br><br>

</body> 

</html>

I managed to get it pass on variables using the alert function to test, but how do you tell what font to use (this example doesn't work unfortunately)?

 

<html> 
<head> 
<title></title> 
<script language="JavaScript">

var x;

function Init() 

{ 
iView.document.designMode = 'On'; 
}

function bold() 
{ 
iView.document.execCommand('bold', false, null); 
}

function italic() 
{ 
iView.document.execCommand('italic', false, null); 
}

function underline() 
{ 
iView.document.execCommand('underline', false, null); 
}

function font(x)
{
if(x == 1) 
{
	iView.document.execCommand('fontname', false, Arial);
                //alert("Test");
}
}
</script>

<body onLoad="Init()">

<FORM ACTION="#" NAME="font2">
<input type="button" onClick="bold()" value="B">
<input type="button" onClick="italic()" value="I">
<input type="button" onClick="underline()" value="U">

<select name="fontChanger" onChange="font(1)">
  <option value="Arial">Arial</option>
  <option value="Tahoma">Tahoma</option>
</select>
</FORM>
<br />

<iframe id="iView" style="margin-top: 20px; width: 200px; height:70px"></iframe> 

<br><br>

</body> 

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.