Results 1 to 6 of 6

Thread: DHTMLWindowsWidget delete functionality

  1. #1
    Join Date
    May 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DHTMLWindowsWidget delete functionality

    1) Script Title: DHTMLWindowsWidget (v1.1)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ndow/index.htm

    3) Describe problem:
    Have been looking to delete (rather than simply close) unused windows widgets using the script...

    var holder = document.getElementById('dhtmlwindowholder');
    var children = holder.childNodes.length - 1;

    for (var x = 1; x <= children; x++) {
    holder.removeChild(holder.childNodes[x])
    }


    however, firefox (2.0.0.11) keeps throwing an error "uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLDivElement.removeChild]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: http://local.secretarium.co.uk/main....ivision_id=61# :: closeWindows :: line 99" data: no]"

    Above, the -1 is because the windows array is 0 bound, but we are starting at 1 (to ensure that the SPAN) div isn't removed - as this caused me loads of problems to begin with.

    Any ideas ?

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Please format any code in your post using the CODE tag. This makes it a lot easier to read it.

    Well, the global array htmlwindow.tobjects[] holds a reference to all DHTML windows (DIV elements) on the page. To remove them, you would do something like:

    Code:
    for (var i=dhtmlwindow.tobjects.length-1; i>=0; i--)
    dhtmlwindow.tobjects[i].parentNode.removeChild(dhtmlwindow.tobjects[i])
    A couple of points. Firstly, you should be looping backwards instead of the standard forward, since as you remove a node, the array collapses by one each time. Secondly, removeChild() should be called on the direct parent of the target you're trying to remove. You can test out the above with something like:

    Code:
    <script type="text/javascript">
    
    function removeall(){
    for (var i=dhtmlwindow.tobjects.length-1; i>=0; i--)
    dhtmlwindow.tobjects[i].parentNode.removeChild(dhtmlwindow.tobjects[i])
    }
    
    </script>
    
    <a href="javascript:removeall()">Remove all windows</a>

  3. #3
    Join Date
    May 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, your help is much appreciated - I'd sussed the need to work backwards thru the array, and had sorta identified that tobjects was the likely contender for the solution.... but nowhere close.

    Tried your suggestion - and although it does the job once, I then get an error when I try to create a new window...

    uncaught exception: [Exception... "Unexpected error arg 0 [nsIDOMWindowInternal.location]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: http://local.secretarium.co.uk/js/wi...dhtmlwindow.js :: anonymous :: line 138" data: no]


    ... where line 138 is ...

    window.frames["_iframe-"+t.id].location.replace(contentsource) //set location of iframe window to specified URL



    which seems to point to

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    There's probably some subtle issue I'm missing here causing the error. From my testing this only occurs in IFRAME based windows right? Ajax or DIV windows after being deleted can be opened again with no errors in FF.

    I'll have to revisit this thread when I have more time, as the solution doesn't jump out right away.
    Last edited by ddadmin; 12-30-2007 at 11:13 PM.

  5. #5
    Join Date
    May 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Indeed, I'm using Iframe windows.

    I've noticed the new "close()" functionality - which, now I understand a little more about "tobject" gives me a work-around - I can simply loop round and "close" all open windows, although this doesn't destroy the window, it does atleast make my life a little easier.

    Appreciate all your help, and look forward to hearing from you again when you have more time.

  6. #6
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    "window.frames["_iframe-"+t.id].location.replace(contentsource) //set location of iframe window to specified URL " comment this and do like below

    t.contentarea.innerHTML='<iframe frameborder="no" src="'+contentsource+'" style="margin:0; padding:0; width:100%; height: 100%;" name="_iframe-"+t.id id="_iframe-"+t.id></iframe>'

    definatly this will solve yopur problem,
    remeber also that you delete the reference of this window when you are going to close the window.if have still problem then feel free to contact.
    thanks

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
  •