0

I don't know how to create an asp in fiddle but I created the JS.Please check the link .Imagine I have a button(button id: button2) on (src : 'ccc.de';), and when i click that button(in ccc.de) I should catch the event in js

My actual src page is not ccc.de, my src page contains an asp with a button(button id: button2) on it.

Thank you in advance

RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53
vinod kumar
  • 15
  • 1
  • 8
  • Possible duplicate of [How to add a onclick event to an element using javascript](http://stackoverflow.com/questions/20018170/how-to-add-a-onclick-event-to-an-element-using-javascript) – Rajesh Jan 27 '16 at 06:30
  • Not a duplicate, I guess – vinod kumar Jan 27 '16 at 07:39

3 Answers3

0

Your question has no relation to angular or JSON for that matter.

If you want to attach an event listener to your button, you can try preventing the default action of the button by doing something like this.

$("#btn").click(function(e){
 e.preventDefault();
 function_to_call();
});
pecey
  • 651
  • 5
  • 13
  • hey sorry for the title I forgot to change the title and thanks for the reply. but I am sorry to say, the solution you gave is not working – vinod kumar Jan 27 '16 at 06:18
  • Can you make a fiddle maybe? I don't see why it should not work. Did you change #btn to whatever the id of the button is? – pecey Jan 27 '16 at 06:25
  • hey I dont know how to create an asp in fiddle but i created the JS please check the link : https://fiddle.sencha.com/#fiddle/14bj imagine i have a button(button ID: button2) on src : 'https://ccc.de', and when i click that button I should catch the event in js Thank you – vinod kumar Jan 27 '16 at 07:07
0

You can do it using event delegation

    $(document).ready(function() {

         $(document).on('click', "#button2", function() {
             alert("button2 clicked");
         });
 });

//instead of document in click event, you should use parent of $button2

Or you can use

 $(document).ready(function() {

         $( "#button2").on('click', function() {
             alert("button2 clicked");
         });
 });
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53
0

Your code are ASP code, or ASP.NET WebForms, maybe ASP.NET MVC?

At fiddle (https://fiddle.sencha.com/#fiddle/14bj) I see iFrame. Remember, if your button in iFrame, and your code with setting event handler in owner document, you should search button for setting your event inside of iFrame. It's will be not fount in parent document. Maybe problem is here. If you have PostBack (or another things, that reloads page), and button2 inside iFrame, then botton2 event handler will be lose after iFrame reloading. So, you will need set listener for event again, because it will be new button2 after reload (inside iFrame).

If you use ExtJS, then better set event on ExtJS button by component config. Somethin like this:

Ext.create('Ext.Button', {
text: 'Button2',
renderTo: Ext.getBody(),
handler: function() {
    alert('You clicked the button 2!');
}});

Here example with two ways: https://fiddle.sencha.com/#fiddle/14hs

For better understood of your problem, culd you provide full code of this pages (if you couldn't use fiddle for asp, use http://pastebin.com/ or another service of posting sources).

I hope I wrote something helpfull (but not shure). Good luck!

Selmaril
  • 746
  • 5
  • 11
  • Thanks for your reply my case a bit different please the whole code my extjs code to create window is http://pastebin.com/Y0X6fqSW (see from line 90) my ASP code that's called in the window is http://pastebin.com/QGKTSC2x (see at line 430 for button) – vinod kumar Jan 27 '16 at 10:16
  • At first look, I see you want close ExtJS window by clicking on button in iFrame: Right? – Selmaril Jan 27 '16 at 12:05
  • What there happens: 1) I added onload handler to iFrame autoEl (look at html) 2) In handler I found the ExtJS window, that contains this iFrame and has found the button in iFrame document. Remember that in iFrame another document, you should search the button exactly in this document. 3) I added handler with js closure, that close the window. This can help you better understand this solution: http://stackoverflow.com/questions/2509934/how-can-i-get-an-element-from-within-a-frameset-frame-using-javascript – Selmaril Jan 27 '16 at 12:59
  • And one more.. Never, NEVER don't call variables in your code 'window' or 'document'. Never don't use names, that alrady used by DOM, language, etc. In your fiddle example you named local variable as 'window'. It's make many problems with debuggong and understandig of code logic in some places. – Selmaril Jan 27 '16 at 13:21
  • Hey bro all at once that worked like a charm millions of million likes – vinod kumar Jan 28 '16 at 12:40