Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts

    Running function in parent

    I have a page I call in a modal window (jQuery Colorbox if it matters) that can be called from one of two different pages. In each page, I want it to have a different affect.

    The page being called is a delete confirmation, and its called from either the list page or the view page. On the list page, it should remove the item from the list, on the view page, redirect to another page.

    The question is, how do I get the different affects to trigger? My thought was simple: have a function unique to each of the two parent pages that shares the same name. The delete page would call the function in the parent, and that function would change the effect. I can't get this to work however.

    I put this in the list page:

    Code:
    $(function () {
    	function deleted() {
    		alert(1);
    	}
    });
    And switched alert(1) for alert(2) in the view page. I then put this on the delete page:

    Code:
    $(function () {
    	parent.deleted();
    });
    But Firebug tells me that parent.deleted() is not a function. I've used parent.document.location.reload(); to refresh pages, so I'm not sure why it doesn't work.

    And is there a better way to work this? Or am I on the right track, just wrong code?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,477
    Thanks
    0
    Thanked 635 Times in 625 Posts
    If it is an actual separate window that is being opened then the original window is called opener and not parent. If it is an overlay inside the current window and not a separate window then the function is in the same window and doesn't need the parent reference that is only needed to access the main page from within a frame.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Move your delete functions outside of $(function.. - they are not accessible globally otherwise.. plus felgall's advice
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by felgall View Post
    If it is an actual separate window that is being opened then the original window is called opener and not parent. If it is an overlay inside the current window and not a separate window then the function is in the same window and doesn't need the parent reference that is only needed to access the main page from within a frame.
    Its a modal iframe within the main window. I had to use parent in order to do things like refresh, why don't I need parent for accessing a function?

    And AndrewGSW, I'll try that and get back to you.

    EDIT: Nope Andrew, didn't work.

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Not sure what I did, but between your advice and my randomly trying combinations, it works!


  •  

    Posting Permissions

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