Что нового

[Сеть, интернет] Получить полную высоту текста на странице в браузере IE

WSWR

AutoIT Гуру
Сообщения
941
Репутация
363
Есть страница в браузере IE, на ней только текст.

Нужно получить полную высоту текста в пикселях.
 

inververs

AutoIT Гуру
Сообщения
2,135
Репутация
465
Есть ли родительский контейнер? Высота текста вместе с междустрочными интервалами? Высота body не подходит?
 

C2H5OH

AutoIT Гуру
Сообщения
1,473
Репутация
333
Код:
#include <IE.au3>

$oIE = _IECreate("http://autoit-script.ru/index.php/topic,16379.msg101035/topicseen.html#new",1)

$oTags = _IETagNameGetCollection($oIE, "div")
For $oTag in $oTags
	If $oTag.classname == "inner" Then
		$iHeight = _IEPropertyGet($oTag, "height")
		MsgBox(0,"высота текста = "&$iHeight,$oTag.innertext)
		ExitLoop
	EndIf
Next


Вообще-то это второй пример отсюда http://autoit-script.ru/autoit3_docs/libfunctions/_iepropertyget.htm
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
WSWR
Страницу можно посмотреть?
 
Автор
W

WSWR

AutoIT Гуру
Сообщения
941
Репутация
363
Есть UDF
http://www.autoitscript.com/forum/topic/143711-marquee-udf-bugfix-release-6-nov-2012/
для работы со встроенным Shell.Explorer.2

Пример
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include 'Marquee.au3'

Global $aMarquee

GUICreate('Marquee Example 1', 320, 220)

$aMarquee = _GUICtrlMarquee_Init()
_GUICtrlMarquee_SetScroll($aMarquee, 0, Default, 'up', 3)
_GUICtrlMarquee_SetDisplay($aMarquee, 2, 'green', Default, 18, 'comic sans ms')
_GUICtrlMarquee_Create($aMarquee, 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & _
		'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & _
		'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' & @CRLF & 'Up and Up...' _
		, 10, 10, 250, 100)

GUISetState()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd

Текст в страницу вписывается с помощью
Код:
.document.write

Нужно получить высоту текста "Up and Up..." в пикселях.
А высота нужна для того, чтобы определить время полной прокрутки произвольного текста.
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
WSWR
Попробуйте так.
Код:
#include<IE.au3>

;~ =================== template test.html ========================
;~ <html>
;~ 	<head>
;~ 	<style>
;~ 		body{
;~ 			border: none;
;~ 			margin: 0px;
;~ 			padding: 0px;
;~ 			}
;~ 	</style>
;~ 	</head>
;~ 	<body>
;~ 	</body>
;~ </html>
;~ ===============================================================

$oIE = _IECreate(@ScriptDir & '\test.html')

$oIE.document.write('Up and Up... Up and Up... Up and Up... Up and Up... Up and Up... Up and Up... Up and Up... ')
$oIE.document.body.style.margin = "0"
$oIE.document.body.style.padding = "0"
$oIE.document.body.style.fontfamily = 'Verdana, Arial, Helvetica, sans-serif'
$oIE.document.body.style.fontSize = "22px"

Local $oTextNode = _IETagNameGetCollection($oIE, 'body', 0)
MsgBox(0, '', _GetTextHeight($oIE, $oTextNode))
_IEQuit($oIE)

Func _GetTextHeight($o_Obj, $o_TextNode)
    
	Local $i_Height = 0

	Local $o_Range = $o_TextNode.createTextRange
	Local $o_Rect = $o_Range.getBoundingClientRect
	$i_Height = $o_Rect.bottom - $o_Rect.top
    Return $i_Height
EndFunc; ==> _GetTextHeight
 
Автор
W

WSWR

AutoIT Гуру
Сообщения
941
Репутация
363
Garrett

Почему-то в случае с Marquee.au3 возвращает высоту встроенного в GUI контрола браузера.

Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include 'Marquee.au3'

Global $aMarquee

GUICreate('Marquee Example 1', 320, 220)

$aMarquee = _GUICtrlMarquee_Init()
_GUICtrlMarquee_SetScroll($aMarquee, 0, Default, 'up', 3)
_GUICtrlMarquee_SetDisplay($aMarquee, 2, 'green', Default, 18, 'comic sans ms')
_GUICtrlMarquee_Create($aMarquee, FileRead(@ScriptDir & '\test.html'), 10, 10, 250, 100)

GUISetState()

Global $oIE = $aMarquee_Params[$aMarquee][1] ; возвращаем объект, созданный _GUICtrlMarquee_Create

$oIE.document.write('Up and Up... Up and Up... Up and Up...  Up and Up... Up and Up... ')
$oIE.document.body.style.margin = '0'
$oIE.document.body.style.padding = '0'
$oIE.document.body.style.fontfamily = 'Verdana, Arial, Helvetica, sans-serif'
$oIE.document.body.style.fontSize = '22px'

Local $oTextNode = _IETagNameGetCollection($oIE, 'body', 0)
MsgBox(0, '', _GetTextHeight($oIE, $oTextNode))


While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd

Func _GetTextHeight($o_Obj, $o_TextNode)

	Local $i_Height = 0

	Local $o_Range = $o_TextNode.createTextRange
	Local $o_Rect = $o_Range.getBoundingClientRect
	$i_Height = $o_Rect.bottom - $o_Rect.top
	Return $i_Height
EndFunc   ;==>_GetTextHeight
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
WSWR
Код:
;~ =================== template test.html ========================
;~ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
;~ <html>
;~ 	<head>
;~ 		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
;~ 		<title>marquee</title>
;~ 			<style>
;~ 				body{margin: 0; padding: 0;}
;~ 				#content{position: absolute; height: auto; visibility: hidden;}
;~ 				#marquee{background-color: #D4D0C8; height: 96px;}
;~ 				.global{margin: 0; padding: 0; width: 300px; font-family: Verdana, Arial, Helvetica, sans-serif;}
;~ 			</style>
;~ 	</head>
;~ 	<body scroll="no">
;~ 		<marquee id="marquee" class="global" behavior="scroll" direction="up"></marquee>
;~ 		<p id="content" class="global"></p>
;~ 	</body>
;~ </html>
;~ ===============================================================

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

GUICreate('Marquee Example 1', 320, 220, -1, -1)
$oIE = _IECreateEmbedded()
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 10, 300, 100)
_IENavigate ($oIE, @ScriptDir & "\test.html")
GUISetState()

$oMarquee = _IEGetObjById($oIE, 'marquee')
;~ $oMarquee.style.fontSize = '8px'
$oMarquee.style.fontSize = '33px'

$oText = _IEGetObjById($oIE, 'content')
;~ $oText.style.fontSize = '8px'
$oText.style.fontSize = '33px'

_IEPropertySet($oText, 'innerText', 'Up and Up...' & _
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...' & _ 
									'Up and Up...')
									
_IEPropertySet($oMarquee, 'innerText', _IEPropertyGet($oText, 'innerText'))
$iHeight = $oText.clientHeight
$iWidth = $oText.clientWidth

MsgBox(0, '', $iHeight &" x "& $iWidth)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
 
Автор
W

WSWR

AutoIT Гуру
Сообщения
941
Репутация
363
Garrett

Спасибо! Вроде подходит.
 
Верх