SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb showmodaldialog & refresh parent

    Hi there,

    I have created a frame that will display the information I want in a showmodaldialog box, so I can use links and forms without it being opened up in a new window.

    What im using it for is to set users preferences, and when the user closes the box I need the parent window to be refreshed so that the settings take effect.

    Can someone help?

    Gav

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    window.onunload = refresh;
    
    funtion refresh()
    {
        opener.getElementById("someID").style.color = 
                   document.getElementById("IDonthispage").value;
    }
    </script>
    </head>

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This won't work because its showmodaldialog(); I need to be able to just refresh the page that opened it.

    Do you know how I can call the page? So if I told it window.name = "test"; on the page I want to refresh, would I be able to refresh it somehow. I've tried doing that and then calling window.test.reload(); but it can't find the page.

    Anything else?

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm...I didn't realize a modal dialog window didn't have an opener property.
    So if I told it window.name = "test"; on the page I want to refresh, would I be able to refresh it somehow. I've tried doing that and then calling window.test.reload(); but it can't find the page.
    A reference to an element is known as a 'pointer' in C++, and it is a numbered location in memory where the html element is located. So, a reference is a number. What you need to do is get that number--you can think of it as a secret code.

    A string like "test" is not a reference/number--it's a string. It's the same old story. You have to repeat three times before you go to bed every night: "a string is not a reference, a reference is a number, so if I have a string, it's not a reference."

    What you need to do is pass the main window's secret code to the dialog window. You can do that using the second parameter of showModalDialog():

    main page:
    Code:
    var window_ref = window;
    showModalDialog("my_dialog_page.htm", window_ref, "dialogHeight:200px;dialogWidth:200px;dialogLeft:100px;dialogRight:100px;");
    Then, you can retrieve that secret code with js in the dialog window, and use the secret code to change the main window. The secret code you passed will be contained in the .dialogArguments property of the dialog window:

    window.dialogArguments


    So, you can do something like this to change the main page:

    window.dialogArguments
    .document.getElementById("my_div").style.backgroundColor="red";
    Last edited by 7stud; Feb 11, 2005 at 18:46.

  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right...

    what I have is a normal html page which is like this... then the user clicks on an options button, this then opens a showmodaldialog, the page that is opened, has framing scripted, and I have basically used asp to fool it, so I use Iframe.asp to show in the box, then top of the frame is iframe.asp?url=about:blank and the bottom is iframe.asp?url=options.asp.

    Now when the user has selected their viewing options they click close ( either my button or the x ) now when they do that I want to use the onUnload function to refresh the page that opened it. So that the options selected take effect.

    Now I can use window.close to close the dialog window, even though it's inside a frame, which I was supprised.

    But how would I be able to refresh the page? Do you know?

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    apologies, I read your post wrong 7stud...

    tried it and it worked great, so I changed it to

    window.dialogArguments.document.history.go(0); and now it refreshes the parent page... added window.close(); on the end and einstien solved the problem...

    Thanks again mate!

    Gav


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •