AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Basic Webpage Controls with JavaScript / COM - Tutorial
Goto page Previous  1, 2, 3 ... 5, 6, 7 ... 15, 16, 17  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  

Do you think this tutorial is beneficial to the AHK Community?
Yeah, I think this tutorial is a great value-add to the Community.
86%
 86%  [ 91 ]
Nope - I think this tutorial is a waste of web space.
0%
 0%  [ 1 ]
I think this tutorial would be better if it incorporated AHK_L & COM_L.
12%
 12%  [ 13 ]
Total Votes : 105

Author Message
rhinox202



Joined: 23 Apr 2009
Posts: 34

PostPosted: Tue Feb 23, 2010 6:45 am    Post subject: Oops! Reply with quote

I know with CSS you can add !important to the code to make it important, but I didn't realize that you couldn't do that in the Javascript implementation. I did some searching and found that I can use setAttribute to do what I want but I'm not quite sure how to rewrite it with COM_Invoke.
Code:
element.setAttribute('style', 'display:inline !important');

I tried a couple of things, but none of them seem to work. Also when I use COM_Invoke(pwb, "Navigate", "javascript: document.getElementById('gsliteswf').previous();") I get a message that says, "Are you sure you want to navigate away from this page?." It seems like that code is changing the address instead of working on the DOM, which is what I intended. Ideas? Thanks.
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Tue Feb 23, 2010 7:05 am    Post subject: Reply with quote

tank would know more about this stuff that I would ( I've never seen !important before ), but you already touched on something that should work. Try:
Code:
url := "javascript: document.all['gsliteswf'].setAttribute('style', 'display:inline !important')"
COM_Invoke(pwb, "Navigate", url)

_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Tue Feb 23, 2010 2:24 pm    Post subject: Reply with quote

this is the first i have ever heard of such but as i look into it it seems hit and miss to be supported in IE therfor whats the point?

I suppose the javascript method is the best way to do it. IMO styles at the tag always take precidence over stylesheet any how so again what really is the point

and finally I am not going to spend any more time on such an obscure and unreliable CSS feature
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
rhinox202



Joined: 23 Apr 2009
Posts: 34

PostPosted: Tue Feb 23, 2010 4:40 pm    Post subject: Reply with quote

jethrow thanks for the idea, but it doesn't seem to work. I am a web designer and !important is neither obscure nor unreliable so I am not sure where you got your information. It works perfectly fine in IE7 (with a doctype) and IE8. If you are interested in learning something, tank, everything you need to know about !important can be found at http://www.electrictoolbox.com/using-important-css/. Thanks anyway, but I guess I'll have to figure this out on my own.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Tue Feb 23, 2010 5:24 pm    Post subject: Reply with quote

i had previously seen that link which plainly states the pains of using IE with it. If your doing data mining with ahk over pages you control you would be better suited to use other than ahk otherwise you better not count on pages having a proper doctype declaration. But whatever knock yourself out with that one and go ahead and beleive its not obscure. I have been a web designer for years now and never heard of it till today and cant imagine a practical use for it
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
rhinox202



Joined: 23 Apr 2009
Posts: 34

PostPosted: Wed Feb 24, 2010 2:45 am    Post subject: Remove "Navigate away from this page?" Reply with quote

Hey Tank... sorry if "pissed you off I have" :-) I figured out a way around needing !important. I have been working on embedding Grooveshark inside an AHK app. Grooveshark, http://www.grooveshark.com, is an online music player. The app has Play/Pause, Next, and Previous buttons in a systray menu which allows Grooveshark to be controlled without being open. As of now everything is fully functional but I get a message saying "Are you sure you want to navigate away from this page?" The message only pops up when I click next or previous in the systray menu. The code being used is as follows and the same thing happens in IE as well as the AHK COM app.

Code:
BROWSER - javascript: function playNext(){document.getElementById('gsliteswf').next();}playNext();

AHK COM - COM_Invoke(pwb, "Navigate", "javascript: function playNext(){document.getElementById('gsliteswf').next();}playNext();")

Am I doing something wrong and is there any way around this message? Thanks.
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Wed Feb 24, 2010 6:16 am    Post subject: Reply with quote

rhinox202 wrote:
The message only pops up when I click next or previous in the systray menu. The code being used is as follows and the same thing happens in IE as well as the AHK COM app.
So, do you still get this message when you use javascript through the url address bar? If so, keep in mind that this is no longer truly an AHK question, but rather a web-development question. If that is the case, this forum isn't necessarily the best place to ask ( though some members may possibly sill answer your question ).
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Wed Feb 24, 2010 6:37 am    Post subject: Reply with quote

Why are you using Navigate for this purpose? Are you unable to use execScript for some reason?

Code:
COM_Invoke(pwb, "execScript", "javascript: function playNext(){document.getElementById('gsliteswf').next();}playNext();")

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Wed Feb 24, 2010 2:54 pm    Post subject: Reply with quote

sinkfaze wrote:
Why are you using Navigate for this purpose? Are you unable to use execScript for some reason?

Code:
COM_Invoke(pwb, "execScript", "javascript: function playNext(){document.getElementById('gsliteswf').next();}playNext();")
take the red out

as far as the use in navigation best to add the following
Code:
javascript: function playNext(){document.getElementById('gsliteswf').next();}playNext();void(0);

_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
rhinox202



Joined: 23 Apr 2009
Posts: 34

PostPosted: Wed Feb 24, 2010 4:51 pm    Post subject: execScript Error Reply with quote

jethrow this problem does occur in the browser address bar as well. It seems like it is in the code somewhere, but I tried searching the JS code and couldn't find anything. Could this be part of JQuery or something? If so would there be a way around it?

sinkfaze/tank thanks for the execScript code. I didn't know about that so I modified the JS alert example at the beginning of this thread. However, this doesn't work and I receive an error saying:

COM Error Notification
Function Name: "execScript"
ERROR: Unkown name.
(0x80020006)
Code:
COM_Invoke(pwb, "execScript", "javascript: function playNext(){document.getElementById('gsliteswf').next();}playNext();")

Above is the code that triggers the error. For the record, I have IE8 installed and the Grooveshark website runs in IE8 Standards Mode. Any ideas?
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Wed Feb 24, 2010 5:36 pm    Post subject: Reply with quote

Quote:
COM Error Notification
Function Name: "execScript"

That's because execScript() is a method of the window object, not the web browser object. Try:
Code:
COM_Invoke(pwb, "document.parentWindow.execScript", "function playNext(){document.getElementById('gsliteswf').next();}playNext();")

That should fix the COM Error, but I'm not sure if this will solve your problem.
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Wed Feb 24, 2010 6:33 pm    Post subject: Reply with quote

cant beleive i missed te execsxript problem putting the crack down now Wink
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
rhinox202



Joined: 23 Apr 2009
Posts: 34

PostPosted: Wed Feb 24, 2010 6:45 pm    Post subject: Reply with quote

Thanks jethrow, that worked perfectly. I had narrowed it down to an "onbeforeunload" event and was working on detaching the event, but this works... so I don't need to.

tank, you seem to have written quite a bit for the COM tutorial, so I was wondering why the "Enter" key doesn't work inside of Flash? I have Grooveshark embedded in the script and if I do a search and press enter nothing happens, I have to click the search button to initiate the search. I used the WinGetClass in the WM_KEYDOWN to get the name and it is "MacromediaFlashPlayerActiveX" instead of "Internet Explorer_Server" but I don't know what that means. I tried adding the Flash name to the if statement but that didn't seem to work. Below is the chunk of code I am referring to.
Code:
WM_KEYDOWN(wParam, lParam, nMsg, hWnd)
{
   If (wParam = 0x09 || wParam = 0x0D || wParam = 0x2E || wParam = 0x26 || wParam = 0x28) ; tab enter delete up down
   {
      ;msgbox, enter pressed
      WinGetClass, Class, ahk_id %hWnd%
      msgbox, %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
      }
   }
}

Thanks so much everyone (tank and sinkfaze). Other than the Enter issue, I have a little more cleanup to do, but once that is done if anyone is interested I will send them the code. Thanks again.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Wed Feb 24, 2010 7:39 pm    Post subject: Reply with quote

I have "0" experience with flash and no practical use for it at this time. So I am a piss poor resource for this issue.
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
Learning one



Joined: 04 Apr 2009
Posts: 1001
Location: Croatia

PostPosted: Fri Mar 26, 2010 9:03 am    Post subject: Reply with quote

First I want to say thanks to Jethrow, Tank, Sean and Sinkfaze for their efforts.
I like to base web control on ElementID, so I wrote a few ElementID based Web page control functions + example for beginners.


Functions:

Code:
;===ElementID based  Web page control functions by Learning one===
WP_SetDDL(pwb, ElementID, ItemNumber) {      ; WP means web page, DDL means DropDownList
   COM_Invoke(pwb, "document.all.item[" ElementID "].selectedIndex", ItemNumber-1)   ; 1 based
}

WP_GetText(pwb, ElementID) {   
   Return COM_Invoke(pwb, "document.all.item[" ElementID "].value")
}

WP_SetText(pwb, ElementID, text="") {   
   COM_Invoke(pwb, "document.all.item[" ElementID "].value", text)
}

WP_Click(pwb, ElementID) {   
   COM_Invoke(pwb,"document.all.item[" ElementID "].click")
}

WP_Navigate(pwb, URL) {   
   COM_Invoke(pwb, "Navigate", URL)
}

WP_WaitToLoad(pwb) {   
   While !(COM_Invoke(pwb,"readyState") = 4)   ; by Jethrow or Sean?
   Sleep, 100
}


Example:
Code:
;===Description=========================================================================
; ElementID based  Web page control example   with explanations      ; by Learning one



;===Settings============================================================================
; Use Compact iWebBrowser3.ahk by Tank to get values below. Look at "Index" value in iWebBrowser3.ahk GUI - that is ElementID.
; Link:                http://www.autohotkey.net/~tank/ahk%20web%20recorder.zip
; AHK forum topic:       http://www.autohotkey.com/forum/topic51270.html

KeywordsBox = 74      ; this means: ElementID of "Keywords Box" is 74
AuthorBox = 86
SortByDropDownList = 152
SearchMessageTitleOnlyRadio = 121
SearchButton = 164

URL = http://www.autohotkey.com/forum/search.php         ; AHK Search address



;===Auto-execute continuation===========================================================
COM_Init()                                       ; Initialize COM
pwb := COM_CreateObject("InternetExplorer.Application")      ; Create new instance of IE and store pointer of web browser in variable pwb
COM_Invoke(pwb , "Visible=", "True")                  ; make IE visible
WP_Navigate(pwb, URL)                              ; navigate to specified URL - web address. "WP" means web page.
WP_WaitToLoad(pwb)                                 ; wait until page is loaded

WP_SetText(pwb, KeywordsBox, "Webpage Controls")         ; set text "Webpage Controls" in "Keywords Box"
WP_SetText(pwb, AuthorBox, "jethrow")                  ; set text "jethrow" in "Author Box"

WP_SetDDL(pwb, SortByDropDownList, 4)    ; "DDL" means DropDownList, "4" means item number 4 - author. So; select item number 4 in "Sort by" DropDown list.
WP_Click(pwb, SearchMessageTitleOnlyRadio)   ; click on "Search message title only" radio
WP_Click(pwb, SearchButton)               ; click on Search Button

COM_Release(pwb)                     ; release object
COM_Term()                           ; terminate COM
ExitApp                              ; press "back" in IE to see what script did.

;===Some other useful lines===
;WP_SetText(pwb, AuthorBox)               ; omit last parameter to clear text from Author Box.
;MsgBox % WP_GetText(pwb, KeywordsBox)      ; shows context of "Keywords Box" in MsgBox
;COM_Invoke(pwb, "Quit")               ; closes IE


;===Functions===========================================================================
#Include Com.ahk         ; COM by Sean


;===ElementID based  Web page control functions by Learning one===
WP_SetDDL(pwb, ElementID, ItemNumber) {      ; WP means web page, DDL means DropDownList
   COM_Invoke(pwb, "document.all.item[" ElementID "].selectedIndex", ItemNumber-1)   ; 1 based
}

WP_GetText(pwb, ElementID) {   
   Return COM_Invoke(pwb, "document.all.item[" ElementID "].value")
}

WP_SetText(pwb, ElementID, text="") {   
   COM_Invoke(pwb, "document.all.item[" ElementID "].value", text)
}

WP_Click(pwb, ElementID) {   
   COM_Invoke(pwb,"document.all.item[" ElementID "].click")
}

WP_Navigate(pwb, URL) {   
   COM_Invoke(pwb, "Navigate", URL)
}

WP_WaitToLoad(pwb) {   
   While !(COM_Invoke(pwb,"readyState") = 4)   ; by Jethrow or Sean?
   Sleep, 100
}


Escape::ExitApp


Last edited by Learning one on Tue Apr 06, 2010 10:36 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 5, 6, 7 ... 15, 16, 17  Next
Page 6 of 17

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group