开发者

Call Javascript function from asp.net page in a frame

开发者 https://www.devze.com 2022-12-08 02:04 出处:网络
I have 2 pages in a frameset, in the first page i have a Javascript Function, the second is an asp.net form with a button, the thin开发者_高级运维g is that I need to call the Javascript function in th

I have 2 pages in a frameset, in the first page i have a Javascript Function, the second is an asp.net form with a button, the thin开发者_高级运维g is that I need to call the Javascript function in the first page when user clicks the button:

I'm trying with:

ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script language=JavaScript>parent.frames[0].Function('parameter')</script>");

There's an alert('...'); in the function but when I call it I don't see anything, apparently the function isn't executed.

¿How can I call the function? Thanks for the help & advises.


Try using FireBug (for firefox, or use FireBug Lite for other browsers) to see the actual HTML and script that each frame has.
Once you conclude the code is created correctly in the ASP.net, continue to use FireBug to see where your script code goes wrong using breakpoints.
If you want a quicker idea, try using some testing in the code you put before calling the function, try this:

alert(parent.frames.length);
alert(parent.frames[0].Function);
parent.frames[0].Function('parameter');


Thanks very much, Dror, for getting me past a time-consuming hassle!

May I add that it looks like one can use the name of the frame in addition to the index (forgive me, folks, if this is obvious):

parent htm:
        :
    <frameset rows="120,*">
        <frame name="OverviewFrame" id="OverviewFrame" src="eoverview.htm">
        <frame name="LegendFrame" id="LegendFrame" src="">
    </frameset>
    <frameset cols="50%,50%">
        <frame name="ControlsFrame" id="ControlsFrame" src="zoomcontrols.htm">
        <frame name="InsetControlsFrame" id="InsetControlsFrame" src="insetcontrols.htm">
    </frameset>
        :

frame htm (insetcontrols.htm):
    parent.frames['OverviewFrame'].enableSync(false);

(where eoverview.htm contains function enableSync(bool))

tested on FF3.6.3, Chrome 4.1.249.1064, Safari 4.0.5, Opera 9.80, IE 8, IE 8 compatibility mode

0

精彩评论

暂无评论...
验证码 换一张
取 消