Что нового

[ Сеть, Интернет ] Работа со строкой адреса в разных браузерах.

EGRUP

Новичок
Сообщения
5
Репутация
0
Как сохранить адрес страницы в переменную?
Как из переменной вписать адрес в адресную строку? (как перейти на указанный в переменной адрес)
Желательно, чтобы работало с популярными браузерами (Опера, Файерфокс, Хром, итд)
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Через DDE:

Код:
#include <Array.au3>

$Ret = _OpenGetURL("", -1, 1, "IExplore")
_ArrayDisplay($Ret, "IExplore")

$Ret = _OpenGetURL("", -1, 1, "FireFox")
_ArrayDisplay($Ret, "FireFox")

$Ret = _OpenGetURL("", -1, 1, "Opera")
_ArrayDisplay($Ret, "Opera")

_OpenGetURL("http://autoit-script.ru", 0, 0, "Opera")

;===============================================================================
;
; Function Name:  _OpenGetURL()
;
; Parameter(s):		$sURL			[optional] Address of page to open,
;									if this is empty string (default), then returned Url from address field of particular tab.
;					$hWin			[optional] Number of tab:
;										-1 = Current tab.
;										0 = New tab (when opening).
;					$RetType 		[optional] Definds returned value:
;										0 = String with Title and URL address.
;										1 = Array with 3 elements...
;											[0] = Title
;											[1] = URL address
;											[2] = String with Title And URL address.
;					$Server			[optional] Serever to open/get Url in/from.
;					$iWait			[optional] Waiting Timeout in milliseconds, on overload will return an error.
;
; Requirement(s):	None
; Return Value(s):	On Success -  See 'Parameter(s)'.
;					On Failure -  Empty string and set @error as following:
;						1 = Error to open Dll (user32.dll)
;						2 = Error Initializing DDE (@extended include more details about the returned value from DllCall).
;						3 = Other DDE Errors (@extended include more details about the returned value from DllCall).
; Author(s):        amel27
;
;=====================================================================
Func _OpenGetURL($sURL = "", $hWin = -1, $RetType = 0, $Server="IExplore", $iWait = 10000)
	Local $ret, $err, $uIdInst = DllStructCreate("int")
	Local $hServer[1], $hTopic[1], $hItem[1], $hConv[1], $hData[1], $sData[1]
	Local $sTopic = "WWW_OpenURL", $sItem = $sURL & ',,0x' & Hex($hWin)
	
	If $sURL = '' Then
		$sTopic = "WWW_GetWindowInfo"
		$sItem = "0x" & Hex($hWin)
	EndIf
	
	Local $hDll = DllOpen("user32.dll")
	If $hDll=-1 Then Return SetError(1, 0, "") ; Error to open Dll
	$ret = DllCall("user32.dll", "int", "DdeInitialize", "ptr", DllStructGetPtr($uIdInst), "ptr", 0, "int", 0, "int", 0)
	If $ret[0] Then Return SetError(2, $ret[0], "") ; Error Initializing DDE
	$hServer = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst,1), "str", $Server, "int", 1004)
	
	If $hServer[0] Then
		$hTopic = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst,1), "str", $sTopic, "int", 1004)
		If $hTopic[0] Then
			$hItem = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst,1), "str", $sItem, "int", 1004)
			If $hItem[0] Then
				$hConv = DllCall($hDll, "int", "DdeConnect", "int", _
					DllStructGetData($uIdInst,1), "int", $hServer[0], "int", $hTopic[0], "int", 0)
				If $hConv[0] Then
					$hData = DllCall($hDll, "int", "DdeClientTransaction", "ptr", 0, "int", 0, _
						"int", $hConv[0], "int", $hItem[0], "int", 1, "int", 0x20B0, "int", $iWait, "ptr", 0)
					If $hData[0] Then $sData = DllCall($hDll, "str", "DdeAccessData", "int", $hData[0], "ptr", 0)
				EndIf
			EndIf
		EndIf
	EndIf
	
	$iErr = DllCall($hDll, "int", "DdeGetLastError", "int", DllStructGetData($uIdInst, 1))
	If $hData[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hData[0])
	If $hConv[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hConv[0])
	If $hItem[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hItem[0])
	If $hTopic[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hTopic[0])
	If $hServer[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hServer[0])
	If $iErr[0] Then Return SetError(3, $iErr[0], "") ; Othe DDE Errors
	DllCall($hDll, "int", "DdeUninitialize", "int", DllStructGetData($uIdInst, 1))
	DllClose($hDll)
	
	If StringRight($sData[0], 3) = ',""' Then $sData[0] = StringTrimRight($sData[0], 3)
	If $sURL = '' Then $sURL = StringRegExpReplace($sData[0], '^"([^"]*?)".*','"\1"')
	
	If $RetType = 1 Then
		Local $iRetTitle = StringReplace(StringTrimLeft($sData[0], StringLen($sURL)+1), '\"', '"')
		Local $RetURL[3] = [StringReplace($sData[0], '\"', '"'), $sURL, $iRetTitle]
		Return $RetURL
	EndIf
	
	Return $sURL
EndFunc
 
Автор
E

EGRUP

Новичок
Сообщения
5
Репутация
0
Спасибо за скорый ответ, буду разбираться.
 

bistriy

Новичок
Сообщения
22
Репутация
0
Re: [ Сеть, Интернет ] Работа со строкой адреса в разных браузерах

А google chrome как добавить.
 

WSWR

AutoIT Гуру
Сообщения
941
Репутация
363
Re: [ Сеть, Интернет ] Работа со строкой адреса в разных браузерах

bistriy

http://autoit-script.ru/index.php?topic=12207.msg79273#msg79273
 

bistriy

Новичок
Сообщения
22
Репутация
0
Re: [ Сеть, Интернет ] Работа со строкой адреса в разных браузерах

WSWR сказал(а):
bistriy

http://autoit-script.ru/index.php?topic=12207.msg79273#msg79273
Ой спасибо большое. Ответ исчерпывающий.
 
Сообщения
142
Репутация
-3
Re: [ Сеть, Интернет ] Работа со строкой адреса в разных браузерах

CreatoR сказал(а):
Через DDE:

Код:
#include <Array.au3>

$Ret = _OpenGetURL("", -1, 1, "IExplore")
_ArrayDisplay($Ret, "IExplore")

$Ret = _OpenGetURL("", -1, 1, "FireFox")
_ArrayDisplay($Ret, "FireFox")

$Ret = _OpenGetURL("", -1, 1, "Opera")
_ArrayDisplay($Ret, "Opera")

_OpenGetURL("http://autoit-script.ru", 0, 0, "Opera")

;===============================================================================
;
; Function Name:  _OpenGetURL()
;
; Parameter(s):		$sURL			[optional] Address of page to open,
;									if this is empty string (default), then returned Url from address field of particular tab.
;					$hWin			[optional] Number of tab:
;										-1 = Current tab.
;										0 = New tab (when opening).
;					$RetType 		[optional] Definds returned value:
;										0 = String with Title and URL address.
;										1 = Array with 3 elements...
;											[0] = Title
;											[1] = URL address
;											[2] = String with Title And URL address.
;					$Server			[optional] Serever to open/get Url in/from.
;					$iWait			[optional] Waiting Timeout in milliseconds, on overload will return an error.
;
; Requirement(s):	None
; Return Value(s):	On Success -  See 'Parameter(s)'.
;					On Failure -  Empty string and set @error as following:
;						1 = Error to open Dll (user32.dll)
;						2 = Error Initializing DDE (@extended include more details about the returned value from DllCall).
;						3 = Other DDE Errors (@extended include more details about the returned value from DllCall).
; Author(s):        amel27
;
;=====================================================================
Func _OpenGetURL($sURL = "", $hWin = -1, $RetType = 0, $Server="IExplore", $iWait = 10000)
	Local $ret, $err, $uIdInst = DllStructCreate("int")
	Local $hServer[1], $hTopic[1], $hItem[1], $hConv[1], $hData[1], $sData[1]
	Local $sTopic = "WWW_OpenURL", $sItem = $sURL & ',,0x' & Hex($hWin)
	
	If $sURL = '' Then
		$sTopic = "WWW_GetWindowInfo"
		$sItem = "0x" & Hex($hWin)
	EndIf
	
	Local $hDll = DllOpen("user32.dll")
	If $hDll=-1 Then Return SetError(1, 0, "") ; Error to open Dll
	$ret = DllCall("user32.dll", "int", "DdeInitialize", "ptr", DllStructGetPtr($uIdInst), "ptr", 0, "int", 0, "int", 0)
	If $ret[0] Then Return SetError(2, $ret[0], "") ; Error Initializing DDE
	$hServer = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst,1), "str", $Server, "int", 1004)
	
	If $hServer[0] Then
		$hTopic = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst,1), "str", $sTopic, "int", 1004)
		If $hTopic[0] Then
			$hItem = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst,1), "str", $sItem, "int", 1004)
			If $hItem[0] Then
				$hConv = DllCall($hDll, "int", "DdeConnect", "int", _
					DllStructGetData($uIdInst,1), "int", $hServer[0], "int", $hTopic[0], "int", 0)
				If $hConv[0] Then
					$hData = DllCall($hDll, "int", "DdeClientTransaction", "ptr", 0, "int", 0, _
						"int", $hConv[0], "int", $hItem[0], "int", 1, "int", 0x20B0, "int", $iWait, "ptr", 0)
					If $hData[0] Then $sData = DllCall($hDll, "str", "DdeAccessData", "int", $hData[0], "ptr", 0)
				EndIf
			EndIf
		EndIf
	EndIf
	
	$iErr = DllCall($hDll, "int", "DdeGetLastError", "int", DllStructGetData($uIdInst, 1))
	If $hData[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hData[0])
	If $hConv[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hConv[0])
	If $hItem[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hItem[0])
	If $hTopic[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hTopic[0])
	If $hServer[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hServer[0])
	If $iErr[0] Then Return SetError(3, $iErr[0], "") ; Othe DDE Errors
	DllCall($hDll, "int", "DdeUninitialize", "int", DllStructGetData($uIdInst, 1))
	DllClose($hDll)
	
	If StringRight($sData[0], 3) = ',""' Then $sData[0] = StringTrimRight($sData[0], 3)
	If $sURL = '' Then $sURL = StringRegExpReplace($sData[0], '^"([^"]*?)".*','"\1"')
	
	If $RetType = 1 Then
		Local $iRetTitle = StringReplace(StringTrimLeft($sData[0], StringLen($sURL)+1), '\"', '"')
		Local $RetURL[3] = [StringReplace($sData[0], '\"', '"'), $sURL, $iRetTitle]
		Return $RetURL
	EndIf
	
	Return $sURL
EndFunc
А не много ли костылей? У Firefox есть XUL, а интерфейс так вообще на JS + HTML. С ним авторы дополнений чудеса вытворяют.
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Re: [ Сеть, Интернет ] Работа со строкой адреса в разных браузерах

ЭйчЭйч
Предупреждение За нарушение общих правил (пункт В.2):
Старайтесь избегать “Over quoting” (преувеличенное цитирование) - цитируйте только необходимую часть сообщения, которая наилучшим образом подчеркнёт суть цитируемого.


С уважением, ваш Администратор.
 
Верх