Posted in ColdFusion | Posted on 01-16-2009 | 5,161 views
Over on cf-talk, a user asked if it was possible to use cfwindow without either centering the window or using a hard coded x, y position. Instead they wanted it relative to where the user clicked. This was rather easy to do so I thought I'd share the code.
First, we need to take a link and simply call a JavaScript function. In order to know where we clicked, we will use two event values:The makeWin function then will do:
2 ColdFusion.Window.create('mywin','Windows Rules','win.cfm',{x:x+25,y:y+25});
3}
And, um, that's it! I thought it would be a bit more complex. The +25 on both x and y will launch the window 25 pixels to the right and down from where you clicked. Adjust accordingly to taste.
The complete template (minus win.cfm) is below:
2
3<script>
4function makeWin(x,y) {
5 ColdFusion.Window.create('mywin','Windows Rules','win.cfm',{x:x+25,y:y+25});
6}
7</script>
8
9<h2>Content to push stuff down</h2>
10
11<h2>More content to push stuff down the page vertically...</h2>
12
13<p>
14This is the test <a href="" onclick="makeWin(event.pageX,event.pageY);return false;">link</a>.
15</p>


http://ui.jquery.com/demos/sortable
I don't think it'll work for CFWINDOW. CFDIV/CFPOD, maybe.
Apparently the "event.pageX" and "event.pageY" are not valid for IE.
Can you shed some light on a fix for this?
Thanks!
<cfajaximport tags="cfwindow">
<script>
function makeWin(x,y) {
ColdFusion.Window.create('mywin','Windows Rules','win.cfm',{x:x+25,y:y+25});
}
</script>
<h2>Content to push stuff down</h2>
<h2>More content to push stuff down the page vertically...</h2>
<p>
This is the test <a href="" onclick="makeWin(event.clientX,event.clientY);return false;">link</a>.
</p>
One last question: Any way to get this to be able to fire off more than once? It seems to only work once, and keeps the position static. The reason I ask is I have the link in two places (top and bottom) but once you click on either of the links it 'sticks' the window where you first clicked.
moveTo used to work in cf8, but no longer does in cf9. I've tried various flavors of setPosition and setPagePosition to no avail. Just wondering.
how i can add to onclick some parameter froma query?
because i have a href into a JS string and i can't use quote or double quote.
<cfset outString &= "<li><a href='##' onclick='makeWin(event.pageX,event.pageY);return false;' >#Left(List.nome_evento,15)#</a> </li> " >
but i need to open in window event on a particular date
This is the test <a href="" onclick="makeWin(event.pageX,event.pageY,#someCFVAR#);return false;">link</a>.
[Add Comment] [Subscribe to Comments]