I am trying to implement an onclick event for an anchor tag on a website from Excel VBA. The following code gives me error message.
Set iePage = ieApp.document
Set ieAnchor = iePage.getElementsByTagName("A").Item(5)
ieAnchor.onclick = true
The error message is a run time error that says Not Implemented
Can someone please advise on getting this event to fire?
BTW, I've used the basic iePage.Links(1).click event without a problem...
but I need to execute a javascript function called from the anchor onclick event.
If I understand your question correctly, you are trying to respond in VBA to the user clicking an anchor? If so you need to create an EventHandler for OnClick event. To do this you must restructure your code to meet the following criteria:
You must declare said Anchor variable using the "WithEvents" keyword in order to respond to events.
To use the "WithEvents" keyword you must declare your Anchor variable at the module level.
You must also be inside a Class module to use the WithEvents keyword.
Finally you need to create the Event Handler itself via the drop down menus in the top of the VBE or just paste in the code below. How to use the code:
Create a Class Module named "MyClass" and paste in the following:
Option Explicit
Private WithEvents ieAnchor As MSHTML.HTMLAnchorElement
Public Sub Main()
Dim iePage As MSHTML.HTMLDocument
Set iePage = ieApp.document
Set ieAnchor = iePage.getElementsByTagName("A").Item(5)
End Sub
Private Function mobjMyAnchor_onclick() As Boolean
''//Your Code Here
End Function
To use the code in the class you can then add a standard module and call the code like this:
Public Sub Example()
Dim objMyClassVariable As MyClass
Set objMyClassVariable = New MyClass
objMyClassVariable.Main
End Sub
Edit:
To call a JavaScript function you can just use the JavaScript URL scheme with the InternetExplorer.Navigate method. Ex: ie.Navigate "JavaScript:SomeFunc()". Or you can actually just cause the click to occur using the HTMLAnchorElement.Click method: ieAnchor.Click.
Related
I am trying to get the URL from inside the second element in the "pShowMore" class.
I have this:
For Each wd In CreateObject("Shell.Application").Windows
If InStr(wd.LocationName, "Institution") <> 0 Then
Exit For
End If
Next wd
Dim newURL As String
newURL = wd.document.getElementsByClassName("pShowMore").getElementsByTagName("a")(1).getAttribute("href")
And I get the error: 438-"Object doesn't support the property or method" for the retrieval (i.e., wd.document.....)
What can I do to get the URL in the href?
Also, why does it not support the property or method?
It turns out I was just getting an error cycling through the open windows.
I used
On Error Resume Next
This solved the specific problem I was having.
I have a problem with using a variable that I declared outside the class, in a class. If I try this, Unity acts as if the variable doesn't exist.
#pragma strict
var chunkWidth=49;
class Chunk{
var width:short;
var position:Vector3;
function Chunk(pos:Vector3){
this.width=chunkWidth; //this gives the error: Unknown identifier: 'chunkWidth'.
this.position=pos;
}
}
This error also occurs when I want to use a function within the class.
You can change a variable in the inspector view if the variable is made public. Put the variable inside the class and make it a public variable. Then go to Unity and click the object that has this component attached. You can then change the variable in before you hit play. The variable will save in unity, but not in your code. So if you use this code with another object the variable will need to be set again in the inspector. But once set Unity will save that value within your project.
I have an C++ application which will take care of script execution. currently i want to execute custom event firing in Vb script and J script. I written code for J Script and working fine, how can i achieve this in Vb Script. (mainly targeting IE)
function customEventFn()
{
alert("sample");
}
var element = document.getElementById("elemneid");
customEventFn.call(element);
Please help me to solve this
Last i found answer to my problem. The above methods does not work in Internet Explorer before version 9. use attachEvent method to register an event handler in earlier Internet Explorer versions. but it wont fire custom event.
you need to install IE9 for correct working of the script.
Add Following tag to the HEAD of the htm file.
-meta http-equiv="X-UA-Compatible" content="IE=9" -
write event body wrapped with function
get reference to an element by using getElementById’
Create custom event and attach that event to the element with call back as function defined in step1.
fire custom event
remove custom event from listener(removeEventListener).
Function CustomFunction()
'function body
End Function
set customFn = getRef("CustomFunction")
set element = document.getElementById("elemid");
element.addEventListener "OnSampleEvent", customFn
set Event = document.createEvent("sampleEvent")
Event.initCustomEvent "OnSampleEvent", false, false, nil
element.dispatchEvent(Event)
element.removeEventListener "OnSampleEvent", customFn
I am still learning PHP so my question may seem a little obvious but...
My question relates to opencart but is probably quite a common practice on many websites. I am creating a opencart module and in that module i have several buttons that complete different tasks. Now I have assigned the button the correct 'href' with the path and appropriate action. eg
$this->data['dosomething'] = $this->url->link('module/modulename/dosomething', 'token=' . $this->session->data['token'], 'SSL');
Note: I have called the module and action a general name for the purposes of my question.
In the controller I then have a private function called 'index', followed by a private function called 'dosomething' like below
public function index() {
* insert code *
}
public function dosomething() {
*insert code*
$this->redirect($this->url->link('module/modulename', 'token=' . $this->session->data['token'], 'SSL'));
}
Now, I would like to know how do I get the button to direct to the module controller and then run the 'dosomething' function. I could put something information in the link, ie action=dosomething and do it this way but most of opencart simply uses the text of the last / as the action. If I use the href stated above I get a error as it is trying to find the controller and template located in 'module/modulename/dosomething' rather than the controller and template located in 'module/modulename' USING the function 'dosomething'.
I hope this makes sense. I see that many other scripts in opencart successfully use this method but I just cant figure out how? I am sure I missing something obvious.
What you are doing is correct. OpenCart's framework will use the third piece of the route if specified as the method. If you try
public function dosomething() {
die('OK');
}
Then go to the url you've got, it should just show a blank white page with OK written on it. My guess is the error doesn't actually relate to the controller being an issue, and more to do with something else you've done. Either that, or the method and the third part of the route aren't a match, or the dosomething method isn't public
What is the effect of making a function Bindable in flex without specifying event name with it? I have done this in my code and it seems to be working alright without any associated event (however it does generate a warning). If I remove the binding from such functions it will does effect the code and doesnt reflect the changes if the return value from the function changes.
Could someone explain me , how and why such Bindable function work even without any event associated with [Bindable] tag.
Example:
<mx:Image id="a" source="{getImage(1)}" useHandCursor="true" buttonMode="true" width="10" height="10" click="finalize(event)" autoLoad="true"/>
[Bindable] private var _ratingSelected:int;
[Bindable]
private function getImage(value:int):String
{
if (value <= _ratingSelected)
return 'images/hr/applicants/star_icon.png';
else
return 'images/hr/applicants/star_icon_dis.png';
}
If I remove the Bindable tag from getImage function here, the image doesnt properly get updated at the run time. Please note that _ratingSelected is Bindable variable here. Even though I don't have any event associated with getImage() function, making it Bindable seems to be working just alright. Does it automatically detect changes to changes in _ratingSelected variable (which is bindable) and call the getImage function at run time? Kindly enlighten.
Thanks.
When you don't specify an event name in the Binding tag, it uses the event "propertyChange". This means that every time the framework gets a "propertyChange" event from your document, it'll try to update the image source by calling getImage again.
Now when the value of _ratingSelected is updated, a "propertyChange" event is dispatched internally, which then causes the image to be updated.
Note that this has nothing to do with whether getImage actually uses _ratingSelected to generate its return value. The only connection between getImage and _ratingSelected from the data binding framework's point of view is the "propertyChange" event which they both claim to dispatch when their respective values have changed (even though getImage never actually dispatches it).