Access <select> in child iFrame from MasterPage (in same domain)
in my ASP.NET application I use a MasterPage and an iFrame for the content part of the application (there is also a sidebar and menubar out of the iFrame).
My goal is to insert a jQuery/javascript function to intercept which <select>
element gets the focus within the child iFrame.
Both MasterPage and iFrame are part of the same application and the iFrame does not open external pages, but .aspx pages of the application, hence same domain.
But anyway the "focus" event seems to be not working, since the inner code is not executed.
Here is the function:
$("#tabFrame").load(function() {
$("#tabFrame").contents().find("SELECT").focus(function() {
alert('focus on');
}).change(function() {
$.ajax({
type: "POST",
url: "../WebService/registerChanges",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
controlName: dropDownId
}),
success: function(data) {
var result = JSON.parse(data.d);
if (result.Success) {
alert("Successfully found.");
}
}
})
})
})
Since the function itself is correct, I guess there are some issues trying to access the inner IFrame from outside, but I cannot figure out w开发者_开发百科hich ones.
Any suggestions? (I use IE8 as browser)
Thanks.
Now it works:
Initially problems were due to the IFrame, since I tried to access it before it was loaded. With $("#tabFrame").load() function it was accessed at the right time.
After that a missing jQuery reference (JSON) was at the origin of the problem :( But making a step behind and put simply alert instead of a WebService call, I could manage this.
The code above is the working version.
精彩评论