Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Basic Webpage Controls with JavaScript / COM - Tutorial


  • Please log in to reply
335 replies to this topic
jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Nice wrapper functions :wink: - have you checked out the iWeb functions?

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Yes I have - great job Tank!

Famous Amos
  • Members
  • 9 posts
  • Last active: Jul 04 2010 04:45 PM
  • Joined: 27 Dec 2009
I've tried messing around to try and get this, but I was unsuccessful. Is there any way to tell if an element exists using this? I want my script to do something to an element only if it exists, because if it doesn't exist, I get a nice COM Error Notification and confirmation if I want to continue.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
com_error(0)after com_init()
Never lose.
WIN or LEARN.

Famous Amos
  • Members
  • 9 posts
  • Last active: Jul 04 2010 04:45 PM
  • Joined: 27 Dec 2009
That's exactly what I was looking for! Thanks! :D

Famous Amos
  • Members
  • 9 posts
  • Last active: Jul 04 2010 04:45 PM
  • Joined: 27 Dec 2009
I have the element id of a text field, how do I retrieve the text?

I'm so close; I just don't know what should go where I have "text?"

test := COM_Invoke(pwb, "document.all.item[ID].text?")
msgbox, %test%


jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Check out Controlling the WebPage on the OP. Depending on the element type, you will use either the value property, or the innerText property:
MsgBox, % COM_Invoke(pwb, "document.all[ID].value")

MsgBox, % COM_Invoke(pwb, "document.all[ID].innerText")


Zork
  • Guests
  • Last active:
  • Joined: --
Hi,

It seems that the Gui browser is malfunctioning at sites which include JavaScript reference to window (e.g. window.mpxfr.document.getElementsByTagName('a'))

To test it I am using the following code:

COM_AtlAxWinInit()
Gui, +LastFound +Resize
;pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),top,left,width,height, "Shell.Explorer") )  ;left these here just for reference of the parameters
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),0,0,510,600, "Shell.Explorer") )
;http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.ole.interop.ioleinplaceactiveobject(VS.80).aspx
IOleInPlaceActiveObject_Interface:="{00000117-0000-0000-C000-000000000046}"
pipa := COM_QueryInterface(pwb, IOleInPlaceActiveObject_Interface)
OnMessage(WM_KEYDOWN:=0x0100, "WM_KEYDOWN")
OnMessage(WM_KEYUP:=0x0101, "WM_KEYDOWN")
gui,show, w510 h600 ,Gui Browser
;take from the IE example
url:="t1.html"
COM_Invoke(pwb, "Navigate", url)
loop
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         break
return

GuiClose:
Gui, Destroy
COM_CoUninitialize()
COM_AtlAxWinTerm()
ExitApp

GuiSize:
WinMove, % "ahk_id " . COM_AtlAxGetContainer(pwb), , 0,0, A_GuiWidth, A_GuiHeight
return
WM_KEYDOWN(wParam, lParam, nMsg, hWnd)
{
;  Critical 20
;tooltip % wparam
  If  (wParam = 0x09 || wParam = 0x0D || wParam = 0x2E || wParam = 0x26 || wParam = 0x28) ; tab enter delete up down
  ;If  (wParam = 9 || wParam = 13 || wParam = 46 || wParam = 38 || wParam = 40) ; tab enter delete up down
  {
      WinGetClass, Class, ahk_id %hWnd%
      ;tooltip % class
      If  (Class = "Internet Explorer_Server")
          {
            Global pipa
             VarSetCapacity(Msg, 28)
             NumPut(hWnd,Msg), NumPut(nMsg,Msg,4), NumPut(wParam,Msg,8), NumPut(lParam,Msg,12)
             NumPut(A_EventInfo,Msg,16), NumPut(A_GuiX,Msg,20), NumPut(A_GuiY,Msg,24)
             DllCall(NumGet(NumGet(1*pipa)+20), "Uint", pipa, "Uint", &Msg)
             Return 0
          }
  }
}

with the following html file:




lavazar mp3











airmp3 free mp3 downloads

lavazar free mp3




lavazar mp3 song for free @ AirMP3







home > lavazar mp3 songs (you are here)


lavazar mp3


  | bookmark airmp3

artist:

song:

         








 

Search in progress, please wait.

Music search results will be displayed in a few seconds.
























 




Copyright©1998-2010 AirMp3 for all your mp3 songs & audio needs.



Link to Us | free mp3 downloads | music charts | top mp3 music downloads

mtv euro top 20 | uk top 40 singles | mtv
us top 20
| billboard top 10
| muchmusic countdown | disclaimer - copyright claims






Does anyone has any idea how to fix it?



Zork
  • Guests
  • Last active:
  • Joined: --
Hi,

It seems that the Gui browser is malfunctioning at sites which include JavaScript reference to window (e.g. window.mpxfr.document.getElementsByTagName('a'))

To test it I am using the following code:

COM_AtlAxWinInit()
Gui, +LastFound +Resize
;pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),top,left,width,height, "Shell.Explorer") )  ;left these here just for reference of the parameters
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),0,0,510,600, "Shell.Explorer") )
;http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.ole.interop.ioleinplaceactiveobject(VS.80).aspx
IOleInPlaceActiveObject_Interface:="{00000117-0000-0000-C000-000000000046}"
pipa := COM_QueryInterface(pwb, IOleInPlaceActiveObject_Interface)
OnMessage(WM_KEYDOWN:=0x0100, "WM_KEYDOWN")
OnMessage(WM_KEYUP:=0x0101, "WM_KEYDOWN")
gui,show, w510 h600 ,Gui Browser
;take from the IE example
url:="t1.html"
COM_Invoke(pwb, "Navigate", url)
loop
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         break
return

GuiClose:
Gui, Destroy
COM_CoUninitialize()
COM_AtlAxWinTerm()
ExitApp

GuiSize:
WinMove, % "ahk_id " . COM_AtlAxGetContainer(pwb), , 0,0, A_GuiWidth, A_GuiHeight
return
WM_KEYDOWN(wParam, lParam, nMsg, hWnd)
{
;  Critical 20
;tooltip % wparam
  If  (wParam = 0x09 || wParam = 0x0D || wParam = 0x2E || wParam = 0x26 || wParam = 0x28) ; tab enter delete up down
  ;If  (wParam = 9 || wParam = 13 || wParam = 46 || wParam = 38 || wParam = 40) ; tab enter delete up down
  {
      WinGetClass, Class, ahk_id %hWnd%
      ;tooltip % class
      If  (Class = "Internet Explorer_Server")
          {
            Global pipa
             VarSetCapacity(Msg, 28)
             NumPut(hWnd,Msg), NumPut(nMsg,Msg,4), NumPut(wParam,Msg,8), NumPut(lParam,Msg,12)
             NumPut(A_EventInfo,Msg,16), NumPut(A_GuiX,Msg,20), NumPut(A_GuiY,Msg,24)
             DllCall(NumGet(NumGet(1*pipa)+20), "Uint", pipa, "Uint", &Msg)
             Return 0
          }
  }
}

with the following html file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>lavazar  mp3</TITLE><meta name="keywords" content="lavazar  mp3, lavazar  free mp3, lavazar music downloads">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<BASE href="http://www.airmp3.net/"><link href="css.css" rel="stylesheet" type="text/css">
<script language="javascript" src="ac.js"></script>
<link rel="stylesheet" type="text/css" href="ac.css" />
</HEAD>
<BODY BGCOLOR=#FFFFFF text="#003366" LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 RIGHTMARGIN=0><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="421" height="148"><a href="http://www.airmp3.net/"><img src="http://www.airmp3.net/i/airmp3.jpg" alt="airmp3 free mp3 downloads" width="421" height="148" border="0"></a></td>
    <td background="http://www.airmp3.net/i/mp3-02.gif" bgcolor="#FF9101"><h1 class="title"><strong> lavazar  free mp3</strong></h1>
      
      <h2 class="title">lavazar      mp3 song for free @ AirMP3 </h2></td>
    <td width="254" height="148"><img src="http://www.airmp3.net/i/mp3-03.jpg" width="254" height="148"></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
     
      <td height="95" align="center" valign="top"><div align="left" style="margin:8px 0px 0px 8px; font-size: 10px;"><a title="free mp3 music downloads" rel="nofollow" href="http://www.airmp3.net/">home</a> > <strong>lavazar  mp3 </strong> songs (you are here) </div>
        
        <h1 style="display: inline;">lavazar  mp3</h1> 
        | <a href="http://www.addthis.com/bookmark.php" rel="nofollow" onClick="window.open('http://www.addthis.com/bookmark.php?pub=airmp3&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'addthis', 'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100'); return false;" title="Bookmark AirMP3" target="_blank"><img src="i/bookmark.png" alt="bookmark airmp3" width="160" height="24" border="0" /></a></td> <td width="180" height="95" align="center" background="i/gradient.jpg" bgcolor="#FEB018"><div style="margin-left:6px;"><form name="search" method="post" action="http://www.airmp3.net/free_mp3_search.php">
artist: <input name="artist" type="text" id="artist2" size="15" style="width:120px;"><div id="aDiv2"></div>
song: <input name="title" type="text" id="title2" size="15" style="width:120px;"><div id="tDiv2"></div><input type="hidden" name="do" value="search">           <input name="search" type="submit" id="search" value="search">
      </form></div></td>
  </tr>
  </table>

<iframe src="collect.php?artist=lavazar&title=&mdf=96fc90e89fbfc93c29056c13c799eaea" border=0 frameborder=0 width=1 height=1>
<script language="JavaScript">
top.location.href="http://airmp3.net/search/lavazar/mp3/_nof";
</script>
<noscript>click below for free mp3 results for<a href="search/lavazar/mp3/_nof"><h1>lavazar  mp3</h1></a>
</noscript></iframe>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="180" height="95" align="center" background="i/bgleftside.jpg" bgcolor="#FEB018"> </td>
      <td align="center"><p><img src="i/divider.gif" /></p>
        <p><font size="5" color="#FF9900"><strong>Search in progress, please wait.</strong></font>
              <font size="3">Music search results will be displayed in a few seconds.</font>
          
          <img src="http://www.airmp3.net/i/wait.gif" width="82" height="10" />
          
          
        </p></td>
  </tr>
  </table> 


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
   
    <td valign="top" bgcolor="#FFFFFF"> 


<div align="center"><iframe marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no src="http://www.airmp3.net/subparts/ad1iframe.htm" width="728" height="90"></iframe></div>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="437" height="32"><img src="i/footer1.jpg" width="437" height="32"></td>
    <td height="32" background="i/footer2.gif"> </td>
  </tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">Copyright©1998-2010 AirMp3 for all your mp3 songs & audio needs.  
 <a rel="nofollow" href="http://www.airmp3.net/link-to-airmp3.php">Link to Us</a> | <a href="http://www.airmp3.net/">free mp3 downloads</a> | <a rel="nofollow" href="http://www.airmp3.net/music-charts.php">music charts</a> | top <a href="http://www.airmp3.net/music-downloads.php">mp3 music downloads</a> 
<a href="http://www.airmp3.net/mtv_europe_charts_free_mp3s_1.php">mtv euro top 20</a> | <a href="http://www.airmp3.net/uk_top40_charts_free_mp3s_1.php">uk top 40 singles</a> | <a href="mtv_us_charts_free_mp3s_1.php">mtv 
  us top 20</a> | <a href="http://www.airmp3.net/billboard_charts_free_mp3s_1.php">billboard top 10</a> 
  | <a href="http://www.airmp3.net/muchmusic_charts_free_mp3s_1.php">muchmusic countdown</a> | <a href="http://www.airmp3.net/disclaimer.htm" rel="nofollow">disclaimer - copyright claims</a>  </td></tr></table>
<script type="text/javascript" language="JavaScript">
var DomainName = '.airmp3.net';

var d = new Date();
var dd = d.getTime();
var ds = String(dd + DomainName);
function CheckIfCookieWasSet() {
var testcookie = '';
if(document.cookie.length > 0) {
	var cookiename = 'MasterRecommendFormCookie=';
	var cookiebegin = document.cookie.indexOf(cookiename);
	var cookieend = 0;
	if(cookiebegin > -1) {
		cookiebegin += cookiename.length;
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		testcookie = document.cookie.substring(cookiebegin,cookieend);
	}	}
if(testcookie == ds) { document.MasterRecommendForm.sc.value = ds; }
else { alert('For email security reasons, your browser must accept cookies before this form can be used.'); }
}
document.cookie = 'MasterRecommendFormCookie=' + ds + '; path=/; domain=' + DomainName;
setTimeout('CheckIfCookieWasSet()',1234);
// -->
</script><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3320311-2");
pageTracker._initData();
pageTracker._trackPageview();
</script>

<script language="javascript">
if(autoCompleter_included) autoCompleter_load();	
</script><script language="javascript">	
var _mpxfra = {
	els : false,
	el : function() {return window.mpxfr.document.getElementsByTagName('a');},
	up : function() {
		this.els = this.el();
		if(this.els.length > 0) {
			for(_mpxi in this.els) {this.els[_mpxi].target='_blank';}
		} else {
			setTimeout(function() {_mpxfra.up();}, 2000);
		}
	}
}
_mpxfra.up();

function _process_a() {
	var _i, _i2, _el;
	for(_i in document.getElementsByTagName('a')) {
		_el = document.getElementsByTagName('a')[_i];
		if(_el.href && _el.href.indexOf('http://'+document.location.hostname+'/download/') == 0) {
			_i2 = parseInt(_i) + 1;
			_el.id = 'dll'+_i2;
			_el.onclick = function() {
				var  _at = 'lavazar';
				var _el2;
				var _id = parseInt(this.id.replace(/^dll/, ''));
				var _idn = _id + 1;
				var _idp = _id - 1;
				document.cookie = 'dl_sl='+encodeURIComponent(document.location.href)+'; path=/';
				document.cookie = 'dl_st='+encodeURIComponent(_at)+'; path=/';
				if(document.getElementById('dll'+_idn)) {
					_el2 = document.getElementById('dll'+_idn);
					document.cookie = 'dl_nl='+encodeURIComponent(_el2.href)+'; path=/';
					document.cookie = 'dl_nt='+encodeURIComponent(_el2.innerHTML.replace(/ mp3$/, ''))+'; path=/';
				}
				if(document.getElementById('dll'+_idp)) {
					_el2 = document.getElementById('dll'+_idp);
					document.cookie = 'dl_pl='+encodeURIComponent(_el2.href)+'; path=/';
					document.cookie = 'dl_pt='+encodeURIComponent(_el2.innerHTML.replace(/ mp3$/, ''))+'; path=/';
				}
				return true;
			}
		}
	}
}
_process_a();
</script>	
</BODY></HTML>

Does anyone has any idea how to fix it?[/code]

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
whats malfunctioning?
is there an error what is it
Never lose.
WIN or LEARN.

Zork
  • Guests
  • Last active:
  • Joined: --
I am getting:

A Runtime Error has occurred.
Do you wish to Debug?

Line: 113
Error: window.mpxfr.document is null or not an object



tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Its not the browser with the error its the page. By default IE suppresses

to do the same with the gui browser

com_invoke(pwb ,"silent",true)

Never lose.
WIN or LEARN.

Zork
  • Guests
  • Last active:
  • Joined: --
I've tried that before posting.
It simply assumes I've answered 'yes' (i.e. that I want to debug) and opens the "Just-In-Time Debugging" screen.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
then the problem is your OS because that is not the behavior it induces

<!-- m -->http://msdn.microsof...y/aa768269.aspx<!-- m -->
Never lose.
WIN or LEARN.

Zork
  • Guests
  • Last active:
  • Joined: --
Thank you very much for your prompt help.