Jump to content

[Solved] Using autoit with tinymce or similar editor


Recommended Posts

I need to edit html and store it in a database (SQLite). The storage of data is no problem, but I would like to edit the html using tinymce editor. This editor runs in javascript and can be opened using IE or similar.

What I would like to do is

* AutoIT is displaying an embedded form (from IE f.ex)

* values are set to form fields and read from fields using my script

* the form should be able to use javascript, because of the editor

Normally these kind of editors can be used with DOM modification without problem to update content.

I am part of the way, but not quite. This is what I have so far:

* window showing html content

* javascript editor opens

* I can MODIFY content (as you can see by running script)

* I can READ content

BUT the screen (IE window) does not refresh :unsure:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 340) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
    $ie = GUICtrlCreateObj($oIE, 10,10, 600,400)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_IENavigate($oie , @ScriptDir & "\t.html")

$oform = _IEFormGetObjByName($oie , "f1")

if @error Then
    MsgBox(0,"",@error)
EndIf

; this is updating the reading but not on screen...
$oarea = _IEFormElementGetObjByName($oform, "ajaxfilemanager")
_IEFormElementSetValue($oarea, "<h1>This is set by AutoIT..</h1>")

; but these two lines can READ the content.. so far so good.
$myContent = _IEGetObjById($oIE, "ajaxfilemanager")
MsgBox(0,"", _IEPropertyGet($myContent, "innertext"))

; the reverse does not seem to do anything.. but I get lots of COM errors but no @error var...
;_IEPropertySet($myContent, "innerhtml", "<h1>This is set by AutoIT..</h1>")
if @error Then
    MsgBox(0,"",@error)
EndIf


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

t.html is my editor form. This works correctly in IE when opened directly.

<html><head>    <title>Ajax File Manager</title>    <script language="javascript" type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>  <script language="javascript" type="text/javascript" src="jscripts/general.js"></script>    <script language="javascript" type="text/javascript">       tinyMCE.init({          mode : "exact",         elements : "ajaxfilemanager",           theme : "advanced",         plugins : "advimage,advlink,media,contextmenu",         theme_advanced_buttons1_add_before : "newdocument,separator",           theme_advanced_buttons1_add : "fontselect,fontsizeselect",          theme_advanced_buttons2_add : "separator,forecolor,backcolor,liststyle",            theme_advanced_buttons2_add_before: "cut,copy,separator,",          theme_advanced_buttons3_add_before : "",            theme_advanced_buttons3_add : "media",          theme_advanced_toolbar_location : "top",            theme_advanced_toolbar_align : "left",          extended_valid_elements : "hr[class|width|size|noshade]",           paste_use_dialog : false,           theme_advanced_resizing : true,         theme_advanced_resize_horizontal : true,            apply_source_formatting : true,         force_br_newlines : true,           force_p_newlines : false,           relative_urls : true        }); </script></head><body>  <form id="f1" name="f1">            <textarea id="ajaxfilemanager" name="ajaxfilemanager" style="width: 50%; ">             <h1>AutoIT Ajax File/Image Manager Plugin</h1>              If this is shown on screen HTML is loaded.          </textarea>         </form></body></html>

Edited by Myicq

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Hi!

you can use $oIE.navigate("URL") to navigate to a specific URL.

Try using

$inputbox = $oIE.document.forms.item("name of item")

$inputbox.value = "new value"

Haven't tested it. :unsure:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Hi!

you can use $oIE.navigate("URL") to navigate to a specific URL.

Try using

$inputbox = $oIE.document.forms.item("name of item")

$inputbox.value = "new value"

Haven't tested it. :unsure:

Thanks for suggestion, but no luck with that.

This updates content, but does not display on screen. So just need to "refresh" the window content.

$oform = _IEFormGetObjByName($oie , "f1")                           ; f1 is my form name
$oarea = _IEFormElementGetObjByName($oform, "ajaxfilemanager")      ; this my object name (form element = textarea)
_IEFormElementSetValue($oarea, "<h1>This is set by AutoIT..</h1>")  ; when read back, the content is actually this..

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Thanks for suggestion, but no luck with that.

This updates content, but does not display on screen. So just need to "refresh" the window content.

But oddly it is like my trials modify a different instance of IE.. because when I manually modify content and read it, it's still the same as when I first loaded the page. so any change in form content is not read.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

when I manually modify content and read it, it's still the same as when I first loaded the page. so any change in form content is not read.

Further test shows that this is TinyMCE not playing correctly with me.. disable it, and updates are correct in a plain textarea.

I will experiment further with this and post solution here.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Solved :huh2:

THANK you to user DaleHohm

Made everything VERY simple...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 700, _
        (@DesktopWidth - 340) / 2, (@DesktopHeight - 580) / 2);, );_
        ;$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
    $ie = GUICtrlCreateObj($oIE, 10,10, 600,400)
    $b = GUICtrlCreateButton("read it",         10,         10+600,50,30)
    $b2 = GUICtrlCreateButton("write it",       10+140,     10+600,50,30)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_IENavigate($oie , @ScriptDir & "\t.html")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $b
            readit()
        case $b2
            writeit()
    EndSwitch
WEnd

func readit()
        $oFrame = _IEFrameGetCollection($oie, 0)
        $i = _IEBodyReadHTML($oFrame)
        MsgBox(0,"",$i)
EndFunc

func writeit()
        $oFrame = _IEFrameGetCollection($oie, 0)
        _IEBodyWriteHTML($oframe, "<h1>Date: " & @MDAY & random(100,999,1) & "</h1>")
EndFunc

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...