PDA

View Full Version : Need help with the dhtmlwindow.js file



vansh110
04-18-2008, 10:55 PM
1) Script Title: dhtmlwindow.js

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

3) Describe problem:
Hello,

I have the dhtmlwindow.js file set up to create dhtml pop ups. It works smooth for the most part. But there is a new functionality that requires me to call a javascript funciton when the user closes the dhtml pop - up. That is, I have to call a function when they click on the little X on top right. I am looking at the dhtmlwindow.js file and figured out the part where it calls the close function, it is around line #210 (approx.) and the code looks like this:

else if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control
{
d.close(this._parent)
}

Now the question I have is that I have to call a function everytime else if (/Close/i.test(sourceobj.getAttribute("title"))) is true. So the code has to look like this:

else if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control
{
d.close(this._parent)
my_function();
}

However, I have to have a condition around my_function() so that my_function() is called only for a certain dhtml pop-up and not for all pop ups.

On a html pop up, you could just do a window.document.href to get the source content of the pop up but this is a dhtml pop up and I cant seem to find the variable that will allow me to do a check on the href attribute to see what the content source of the pop up is.

This would be a great help indeed if you can point me in the right direction. thanks!

ddadmin
04-19-2008, 01:38 AM
Hmmm is there a reason why you aren't simply using the onclose() event handler of DHTML window to run your custom function when a window is closed? With regards to getting the URL of the document inside a DHTML window, assuming you're using the IFRAME option, you could use the code window.frames["_iframe-"+t.id] to reference the IFRAME window as a FRAME object.

Altogether, here's an example:


var mywin=dhtmlwindow.open("pagebox", "iframe", "test.htm", "My Web site", "width=590px,height=350px,resize=1,scrolling=1,center=1", "recal")

mywin.onclose=function(){ //Run custom code when window is being closed (return false to cancel action):
alert("The DHTML window you're about to close contains the URL "+window.frames["_iframe-pagebox"].location.href)
return true //allow closing of window to proceed
}

The key to realize though is that you can only probe window.frames["_iframe-"+t.id] if the document contained inside the IFRAME belongs to the same domain as the page containing the DHTML wndow. Otherwise, a call to window.frames["_iframe-"+t.id].location will silently throw an error instead, as cross domain access isn't allowed in JavaScript.

vansh110
04-22-2008, 07:11 PM
Thank you so much, that did it. I still dont know why it works only with 'pagebox' but it works! Thanks again.

ddadmin
04-23-2008, 07:07 AM
pagebox is just the arbitrary ID I gave my instance of DHTML window above (1st parameter within dhtmlwindow()). It shouldn't matter what you change this name to actually, as long as your code that follows is changed as well to reference the new name where applicable.