0

I got a page which has an iframe. This page has a masterpage on which there is a js function defined.

masterpage contains:

  <script type="text/javascript" src="/somejs.js"></script>

page with iframe:

  <div >
    <iframe id="myIframe" runat="server"></iframe>
  </div>

how can i call functions in the 'somejs.js' file?

2 Answers 2

1

If both documents are from the same domain, you can simply call like

window.parent.someFunction();

Otherwise it's the whole different story.

Sign up to request clarification or add additional context in comments.

Comments

0

I am not quite clear.

You have a page.master which has <script type="text/javascript" src="/somejs.js"></script>

Then a default.aspx with

<div >
    <iframe id="myIframe" runat="server"></iframe>
</div>

In your iframe, i think you want to show some other page.

So, if you want ur javascript outside iframe,

you can just call it normally like onload=function1();

Coz when default.aspx is converted to html, it takes everything from master page including ur declaration for javascripts..

Another way is that you can call it from codebehind .cs file.

Eg,

Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl(@"js\common.js"));
        if (!Master.Page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            Master.Page.ClientScript.RegisterStartupScript
                (this.GetType(), "alert", "initHomeTabsLoad();", true);
        }

But if you want ur javascript inside ifram, it's another story as you need to call that script on that original page.

1 Comment

what do you want ur javascript to do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.