Jump to content

_IECreateEmbedded and CSS [SOLVED]


MrBeatnik
 Share

Recommended Posts

Hi folks.

Hope someone can assist!

I have a LOCAL web file, with CSS included.

If I run the file in a browser, the CSS formats correctly to the markup - colour/text size etc is all seen as defined in the CSS.

When I used AutoIT to embed this page, there is no formatting.

Can anyone point out why?

Thanks.

$oIE = _IECreateEmbedded ()
$mainGUI = GUICreate("test", 699, 264, (@DesktopWidth/2)-(699/2),(@DesktopHeight/2)-(264/2),$WS_CAPTION)
$GUIActiveX = GUICtrlCreateObj($oIE, 21, 102, 656, 144)
GUISetState(@SW_SHOW)

Local $file = FileOpen("H:\test.htm", 0)

If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
Local $chars = FileRead($file)

FileClose($file)

_IENavigate ($oIE, "about:blank")
_IEDocWriteHTML ($oIE, $chars)
_IEAction ($oIE, "refresh")

<!-- HTML CODE -->
<html>
<head>
</head>
<link href="mycss.css" rel="stylesheet" type="text/css" media="screen" />
<body>
<p id = 'test'>test</p>
</body>
</html>

<!-- CSS CODE -->
p#test{color: #9F6000;}

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

probably cos your writing name of css after loading the page

try to add it in-line in htm file

<style type="text/css" media="screen">#test{color: #9F6000;}</style>

instead trying to load css when already opened

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

probably cos your writing name of css after loading the page

try to add it in-line in htm file

<style type="text/css" media="screen">#test{color: #9F6000;}</style>

instead trying to load css when already opened

That way works, but I have quite a large CSS file and multiple HTML files, and would prefer to link it as per supported HTML methods (saves repeating code per page, and I can change code centrally; this is much better method).

Do you know if the link method is or is not supported with AutoIT?

I have attempted various methods of link (full path i.e. H:name.css, semi-path i.e. .name.css).

If the other ways are not supported with AutoIT, then I'll add it in, but I don't like it

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

mu suggestion is for you to try to add aditional lines on preloaded page

eg.

predefine css in htm file as

<!-- HTML CODE -->

<html><head></head>

<link href="mycss.css" rel="stylesheet" type="text/css" media="screen" />

and call that page on reditect with autoit

and after it insert html code

so instead

_IEDocWriteHTML ($oIE, $chars)

use

_IEDocInsertText ($oIE, "<body><p id='test'>test</p></body></html>")

or something similar, if you code it correctly it shud work with no errors

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

mu suggestion is for you to try to add aditional lines on preloaded page

eg.

predefine css in htm file as

<!-- HTML CODE -->

<html><head></head>

<link href="mycss.css" rel="stylesheet" type="text/css" media="screen" />

and call that page on reditect with autoit

and after it insert html code

so instead

_IEDocWriteHTML ($oIE, $chars)

use

_IEDocInsertText ($oIE, "<body><p id='test'>test</p></body></html>")

or something similar, if you code it correctly it shud work with no errors

Hmmn, a little confusing. I understand what I need to do (I think!), but it seems strange that:

> The text that is written to the page (using _IEDocWriteHTML) is done after the webpage has been processed, so no formatting is applied to this new text. To me, this almost makes _IEDocWriteHTML a bit useless, except for maybe some debugging purposes etc... but I'm sure others have good uses for it.

> Whereas _IEDocInsertText, although still written to the page after it has been processed, somehow does get formatted.

OK.

Sure this works fine:

_IENavigate($oIE, "file:///H:/test.htm")

I would therefore think that this code would update the page, using the loaded CSS:

Local $oBody = _IETagNameGetCollection($oIE, "body", 0)
_IEDocInsertText($oBody, "<p id = 'test'>test2!</p>", "beforeend")

...but there are issues (in fact the page redirects to google with the required output code in the search bar!) It seems the tags are not processed.

Looking at the help file for _IEDocInsertText, it seems this should be possible..., but I'm still having issues. Well, at least I'm on the right track - need to keep at it. In the mean time, if anyone has other hints that would be great.

Thanks for the poke in the right direction bogQ!

-EDIT- Sorry for multiple edits whilst people are reading.

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

Hi,

I'm not an expert for html, but belongs a style sheet not normaly to the header? In your code it hangs between header and body.

You may have a look at the attached standard example.

best regards, Reinhard

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
 
<head>
<title>Link-Element for Stylesheets</title>
<link rel="stylesheet" type="text/css" href="formate.css">
<style type="text/css">
/* ... your file specific formats ... */
</style>
</head>
 
<body>
<h1>Link-Element for Stylesheets</h1>
</body>
</html>
Edited by ReFran
Link to comment
Share on other sites

Got it... I think.

_IEDocInsertText is not much use when trying to insert HTML with tags that will be processed by CSS.

_IEDocInsertHTML inserts the text and processes the tags correctly.

#include<ie.au3>
#include <WindowsConstants.au3>

$oIE = _IECreateEmbedded ()
$mainGUI = GUICreate("test", 699, 264, (@DesktopWidth/2)-(699/2),(@DesktopHeight/2)-(264/2),$WS_CAPTION)
$GUIActiveX = GUICtrlCreateObj($oIE, 21, 102, 656, 144)
GUISetState(@SW_SHOW)

_IENavigate($oIE, "H:test.htm") ;Navigate to base file which includes CSS.
$testText = "<p id = 'test'>test2!</p>" ;The ID "TEST" refernces CSS on the above page.

Local $oBody = _IETagNameGetCollection($oIE, "body", 0)
_IEDocInsertHTML($oBody, $testText, "beforeend")

bogQ, thanks for taking time here to help - your assistance got me on the right track!

ReFran, thanks for taking the time to help me out!

Yes, markup should be in the HEAD, but it is still processed either way (it's just sloppy outside head and my mistake on quick example coding, so I will move it!).

Seems like the main problem is solved with the above code.

-EDIT- modified AU3 code as I copied the wrong test section.

post-12112-0-42068100-1355222403_thumb.p

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

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...