I have a code that clicks an html element but it doesn't fire its java script code, in VBA I used to call "initEvent" in order to invoke a java script event.
I have searched the web and haven't found a suitable solution.
There's a working solution, but it's not quite useful in most cases, placing a java script code in the url and navigating to it, however there's a need for the location of the html element which is a problem sometimes.
The code I use in order to do a click in the html element :
el.InvokeMember("onclick");
Also tried :
el.InvokeMember("click");
The code that I place in the url and find not too much useful :
wb.Navigate("javascript: document.getElementsByClassName('something')[0].click();void(0);");
I hope to receive a working solution, thanks in advance.
I've solved it, a very original solve I'd say.
So basically, I've thought about it this way.
Finding an element that I already have is not comfortable at all, so the java script navigate didn't seem useful, however, I thought of changing it to fit any element, the question was how.
The answer I came up with, what if I'd focus the specific element and then use a javascript to click on the focused element, and it worked.
So the fixed code :
el.Focus();
wb.Navigate("javascript: document.activeElement.click();void(0);");
I hope it'll be useful to some of you.
Related
I am alien to javascript so pardon me for any naive mistake you find (though that's what I am looking for).
I tried to replicate the code provided for testing the button click event for plotly, but it's not getting fired.
Link from which code is imported:
https://plot.ly/javascript/custom-buttons/#bind-button-events-to-plotlyjs-charts
The way I used it in my html file to test it is shown in the image attached. It works well in code snippet, but due to some mistake of mine in using the javascript in the same page, I am not able to get in work.
Assistance highly appreciated.
the cdn link to jquery wasn't working.
Never rely on the external, keep a local copy of all libraries and call them
I'm currently working on a web editor where you can enter your HTML, CSS and JavaScript code and see the result in real time. Something similar to JSBin or JSFiddle. (I'm doing that to get an offline editor)
I've already been through many problems especially when it comes to CSS but I solved them by using an iframe and injecting all my code into it. And that works amazingly well until you type some JavaScript.
I'm sending the code between <script></script> but unlike CSS it won't run. What's very weird is that when I enter something like $('button').css('color', 'red');, the buttons of the editor effectively get affected but not those of my iframe. Exactly the opposite of what I expected. I've tried many things, looked at many topics on the forum, but nothing works. I also tried to load a blank page in my iframe. In that case, JavaScript runs but it becomes impossible to edit the code in the iframe! What's going on? Where am I going wrong? Thank you in advance for your help!
Here's my editor : https://jsbin.com/tuqite/edit?html,js,output/
Try updating the content of the iframe like this.
// this string contains both html and script
var html_string= "content";
document.getElementById('childFrame').src = "data:text/html;charset=utf-8," + escape(html_string);
By directly updating the iframe DOM like the way you are doing may not be the right way .
Is it possible to find out (in Chrome/FireFox) that which Javascript file (and hopefully line number) is being used on a web page by a specific element?
Thanks
The question is a bit unclear, but I can show you how to watch a particular element for JavaScript interaction in Chrome:
Then, after you do that, watch as we click the checkbox:
Some reference for Chrome: https://developers.google.com/chrome-developer-tools/docs/overview
Most other browser work in a similar fashion. There are also other ways to find out how JavaScript code is interacting with your page, but you'll need to give me a more specific scenario to answer that.
I have a div with a <script scr='highcharts.js'> that is embedded in the code of that div.
My application will rewrite the source of that DIV every now and then, and write a bunch of new code. It will also rewrite the tag. Every thing works fine (highcharts is working). But because of some other constraints it is quite difficult to write the tag in the main body of the page. (It will take to long to explain exactly why... I hope my question can be answered without :-) )
The strange thing is: when I look with firebug, I can tell the script is being reloaded everytime I rewrite the source of the DIV! There is even some kind of id added to the URL:
/highcharts.src.js?_=1328861301862
I'm not doing this! I don't recognize the ID as anything in my app... It seems that every browser is doing this, so it is not specific to FF. Why is this happing, and is there any way to prevent this?
If anyone wonders how I solved this: I ended up using require.js. This solved the problem neatly :-)
I have an html page, and I need a link to show that the user would be going to 'example.html', when really, the link goes to 'javascipt:ajaxLoad(example.html);'.
I tried this:
Example
But it didn't work. Any help? I already asked the webmasters stackexchange, and they told me that this would be a javascript programming question. Not an html question.
Example
By returning false you prevent the default action. And this way the links will still work when javascript is disabled, but then you don't get the AJAX functionality.
Just point the href at the actual file. The javascript onclick will take precedence - as long as you take care to disable the actual click effect by doing a "return false" or similar, the status bar will show 'example.html' and not the javascript url.
As well, note that it should be javascript:... (you're missing an r). The onwhatever attributes are already assumed to be javascript, so you could just say onclick="ajaxLoad(...) anyways.
Look, I'm not sure if I got exactly what you're asking about here, but the following fix often works with me. Just change the double-quotes to single-quotes, and put double-quotes around the example.html part
<a href="example" onclick='javascipt:ajaxLoad("example.html");'>Example</a>