/    Sign up×
Community /Pin to ProfileBookmark

accessing the root window

i have these windows structure:

for this structure:
root_window -> window1(opened by root_window using window.open)

  • root_window can be accessed from window1 by doing “window.opener”
  • How about for this?
    root_window -> window1(opened by root_window using window.showModalDialog)

    how do i access the root_window from window1?

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @TheBearMayOct 08.2008 — showModalDialog is opened in a new address space and is not connected to its opener. You can pass information to the modal window, but it's a one way street.

    http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
    Copy linkTweet thisAlerts:
    @dongzkyauthorOct 09.2008 — hi all,

    what i really want is to be able to access the variables, functions, etc. in the main window from the opened window(using showModalDialog). I have come up a way in doing it and just wanna share. You need to pass arguments when using showModalDialog. For my purpose, since I want to access the elements in the root window, I do it this way:

    root_window:

    window.showModalDialog("modal02.cfm",window,"resizable:no;dialogWidt:50;dialogHeight:50");

    the opened window:

    function closeModal()

    {

    //to replace the URL of the root window, you can do this

    dialogArguments.top.location.href = "http://www.webdeveloper.com";

    window.close();

    }


    -------------------------------------------------------
    Of coure, if you want to pass other arguments aside from the window object, you might also wanna do this:

    root_window:

    var objArg = new Object();

    objArg.testing = "test only";

    objArg.rootwindow = window;

    for the opened window:

    function closeModal()

    {

    alert("testing value = " + dialogArguments.testing);

    dialogArguments.rootwindow.location.href = "http://www.webdeveloper.com";

    window.close();

    }

    And it works fine with me.
    Copy linkTweet thisAlerts:
    @dongzkyauthorOct 09.2008 — Sorry, i forgot to add the showModalDialog function in the root_window for the post above, so i am rewriting, coz i can't seem to edit my previous post.

    If you want to pass other arguments aside from the window object, you might also wanna do this:

    int the root_window:

    var objArg = new Object();

    objArg.testing = "test only";

    objArg.rootwindow = window;

    window.showModalDialog("modal02.cfm",objArg,"resizable:no;dialogWidt:50;dialogHeight:50");


    for the opened window:

    function closeModal()

    {

    alert("testing value = " + dialogArguments.testing);

    dialogArguments.rootwindow.location.href = "http://www.webdeveloper.com";

    window.close();

    }

    And it works fine with me.
    ×

    Success!

    Help @dongzky spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...