PDA

View Full Version : DHTMLWindowsWidget delete functionality



zac
12-29-2007, 10:00 AM
1) Script Title: DHTMLWindowsWidget (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/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.pl?competition_id=18&classdivision_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 ?

ddadmin
12-29-2007, 11:56 PM
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:


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:


<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>

zac
12-30-2007, 02:19 AM
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/windowfiles/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

ddadmin
12-30-2007, 03:44 AM
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.

zac
12-30-2007, 11:44 AM
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.

shahdeveloper
11-17-2008, 12:46 PM
"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