[JS] Undo / Redo van MSHTML via functie aanroepen

Pagina: 1
Acties:

  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Ik ben bezig met een webbased wysiwyg html editor (IE ONLY!).
Ik gebruik dus contentEditable, waardoor je via MSHTML gewoon HTML kan editen.

Undo en redo werken wel, als je gewoon op CTRL+Z en CTRL+Y drukt, maar....
Ik wil ook via een functie kunnen undo'en of redo'en, dus dat als de gebruiker op een undoknopje klikt dit gebeurt.
Ze zitten helaas (nog) niet verwerkt in execCommand(), wel zitten ze in de DHTML component, maar activeX is uitgesloten!

Ik heb al gezocht op een manier om een soort van keydown event te triggeren. Toen kwam ik uit op fireEvent(), maar die ondersteunt blijkbaar geen keydown event, waarschijnlijk vanwege bepaalde security overwegingen.

Weet iemand misschien of het toch mogelijk is wat ik wil?

twitter.com/curly_sanders


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

werkt execCommand ( "undo" ) niet :? Da's nieuw voor mij...

Krijg je dan een foutmelding oid :?

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Verwijderd

document.execCommand("undo", false, null)
edit:

oeps te laat

[ Voor 37% gewijzigd door Verwijderd op 23-06-2003 13:08 ]


  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Undo
Not currently supported.
van: http://msdn.microsoft.com.../reference/commandids.asp

ik heb t getest en hij doet gewoon niks... ook geen fout ofzo

twitter.com/curly_sanders


Verwijderd

vreemd bij mij doet IE het wel. (in een iframe)

[ Voor 3% gewijzigd door Verwijderd op 23-06-2003 13:51 ]


  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Dat is dan wel heel bijzonder, want t werkt echt niet!

twitter.com/curly_sanders


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Dope-E:
Dat is dan wel heel bijzonder, want t werkt echt niet!
Kan je even een voorbeeldje online zetten, want zo blijft het voor ons gissen wat er nou niet goed gaat...

Ik weet iig 100% zeker dat 't bij mij wel werkt, dus een "not implemented" probleem kan het @ IE6 iig niet zijn ....

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Ik heb t volgende in de pagina staan:

een Iframe:
HTML:
1
2
<iframe id="editpage" name="editpage" width="100%">
</iframe>


een script om het editable te maken:
JavaScript:
1
2
3
4
5
6
var bodyTag = '<body style="margin: 0"><html></html></body>';
editpage.document.open();
editpage.document.write(bodyTag);
editpage.document.close();
editpage.document.body.contentEditable = true;
editpage.focus();


en dan gewoon de volgende functie aanroep:
JavaScript:
1
editpage.document.execCommand('Undo', false, null)


Op deze manier wordt ook alle andere execCommand() uitgevoerd, voor Bold, Italic, enz...
die dus allemaal wel werken!

[ Voor 13% gewijzigd door Dope-E op 23-06-2003 15:40 ]

twitter.com/curly_sanders


  • Bosmonster
  • Registratie: Juni 2001
  • Laatst online: 19-08 22:14

Bosmonster

*zucht*

Niet op het iframe doen, maar op het hoofddocument.

dus alleen

document.execCommand('Undo');

Dan werkt het als het goed is wel.. op het iframe direct wordt volgens mij ook nog niet ondersteund.

  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Nou Bos...
T werkt nu maar dan af en toe... 8)7
tis echt heel duister :?

Ik heb t maar ff op mijn webspace gezet zodat jullie r misschien wijzer uit kunnen worden:
http://members.chello.nl/akrul/got/editor.htm

twitter.com/curly_sanders


  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
*kickje*
Mischien dat iemand r nog even naar wil kijken?

twitter.com/curly_sanders


  • Bosmonster
  • Registratie: Juni 2001
  • Laatst online: 19-08 22:14

Bosmonster

*zucht*

Wazig.. bij mij werkt die nooit.. als ik het even in een los bestand doe zoals ik het zelf heb, werkt het prima..

test.html:

code:
1
2
3
4
5
6
7
8
<html>
<body>
<a href="javascript://" onclick="document.execCommand('Undo')">Undo</a> | 
<a href="javascript://" onclick="document.execCommand('Redo')">Redo</a>
<iframe src="content.html">
</iframe>
</body>
</html>



content.html:

code:
1
2
3
4
<html>
<body contenteditable>
</body>
</html>



Hier werkt het prima.

  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Op die manier werkt ie idd perfect... Ik g m proberen om te bouwen tot die manier.

thx again bosmonster!

twitter.com/curly_sanders


  • Dope-E
  • Registratie: Januari 2001
  • Laatst online: 11-07 12:42

Dope-E

The one and only Dope

Topicstarter
Het wordt me niet echt duidelijker, maar ik heb wel ontdekt dat als de volgende table er in staat t misgaat:
HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<a href="javascript://" onclick="callFormatting('Undo')">Undo</a>
<a href="javascript://" onclick="callFormatting('Redo')">Redo</a>
<table width="638" border="0" cellspacing="0" cellpadding="1" bgcolor="#E1DFE3">
  <tr>
    <td colspan="2" height="22" class="knoppenbalk"> 
      <table border="0" cellspacing="0" cellpadding="0" bgcolor="#E5E4E8">
        <tr>
          <td>[img]"images/new_default.gif"[/img]</td>
          <td>[img]"images/open_default.gif"[/img]</td>
          <td>[img]"images/save_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/code_default.gif"[/img]</td>
          <td>[img]"images/preview_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/cut_default.gif"[/img]</td>
          <td>[img]"images/copy_default.gif"[/img]</td>
          <td>[img]"images/paste_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/undo_default.gif"[/img]</td>
          <td>[img]"images/redo_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/link_default.gif"[/img]</td>
          <td>[img]"images/image_default.gif"[/img]</td>
          <td>[img]"images/table_default.gif"[/img]</td>
        </tr>
      </table> 
    </td>
  </tr>
  <tr>
    <td colspan="2" height="1"></td>
  </tr>
  <tr>
    <td colspan="2" height="22" class="knoppenbalk"> 
      <table border="0" cellspacing="0" cellpadding="0" bgcolor="#E5E4E8">
        <tr>
          <td>
            <div onMouseOver="setStatus('Lettertype')" onMouseOut="setStatus('')">
            <select  name="font" id="font" class="buttons" onChange="callFormatting('FontName',this.value)">
              <?
                $q = "SELECT naam_html, naam_windows FROM font ORDER BY naam_windows";
                $result = mysql_query($q);
                while($row = mysql_fetch_assoc($result)) echo "<option value=\"".$row["naam_html"]."\">".$row["naam_windows"]."</option>\n";
              ?>
            </select>
            </div>          
          </td>
          <td width="1"></td>
          <td>
            <div onMouseOver="setStatus('Tekengrootte')" onMouseOut="setStatus('')">
            <select  name="fontsize" id="fontsize" class="buttons" onChange="callFormatting('FontSize',this.value)">
              <option value="1">10</option>
              <option value="2">13</option>
              <option value="3" selected>16</option>
              <option value="4">20</option>
              <option value="5">24</option>
              <option value="6">32</option>
              <option value="7">48</option>
            </select>
            </div>
          </td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/bold_default.gif"[/img]</td>
          <td>[img]"images/italic_default.gif"[/img]</td>
          <td>[img]"images/underlined_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/left_default.gif"[/img]</td>
          <td>[img]"images/center_default.gif"[/img]</td>
          <td>[img]"images/right_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/olist_default.gif"[/img]</td>
          <td>[img]"images/ulist_default.gif"[/img]</td>
          <td>[img]"images/outdent_default.gif"[/img]</td>
          <td>[img]"images/indent_default.gif"[/img]</td>
          <td width="5" align="center">[img]"images/spacer.gif"[/img]</td>
          <td>[img]"images/backcolor_default.gif"[/img]</td>
          <td>[img]"images/textcolor_default.gif"[/img]</td>
        </tr>
      </table> 
    </td>
  </tr>
</table>

Via de linkjes die bovenaan staan gaat t dan ook niet goed!
Verder heb ik de volgende functie nog (waar t zeker niet aan ligt!):
JavaScript:
1
2
3
4
function callFormatting(sFormatString,val){
    if(val) document.execCommand(sFormatString,false,val);
    else document.execCommand(sFormatString);
}

en het Iframe:
HTML:
1
2
<iframe id="editpage" name="editpage" width="100%" src="content.php">
</iframe>

Als de tabel in t eerste stukje code niet aanwezig is of met <!-- --> gecommented werken de linkjes dus wel goed!

Wat kan ik nou veranderen in die table dat t wel werkt?

BTW: Ik heb op elk plaatje in de table ook al Unselectable="on" geprobeerd, maar dat had ook geen effect. :(

[ Voor 35% gewijzigd door Dope-E op 25-06-2003 13:17 ]

twitter.com/curly_sanders

Pagina: 1