Page 1 of 2

close a window that has no handler

Posted: Tue Jul 13, 2004 6:57 pm
by mcog_esteban
hi all.
can someone tell me how can close a popup window that has no handler?
ex:
<html>
<body>
<script>
window.open("http://forums.devnetwork.net")
</script>
</body>
</html>

without clicking on the X icon :D

Posted: Tue Jul 13, 2004 7:00 pm
by markl999
<a href="javascript:window.close()">close window</a>

?

Posted: Tue Jul 13, 2004 7:01 pm
by feyd
window.close() generally...

wow.. was I behind a ways on that one.. :P

Posted: Tue Jul 13, 2004 7:07 pm
by mcog_esteban
yes...but i wanna do it in the parent window.
without buttons or links,isn“t any way to get any info about the child window(id,etc) and closing it using DOM or something else?

Posted: Tue Jul 13, 2004 7:11 pm
by feyd
the info is returned from window.open..

Code: Select all

var windowref = window.open("whatever");


windowref.close();

Posted: Tue Jul 13, 2004 7:25 pm
by mcog_esteban
in that case we have a handler...i asked without.
take a look the new example.

<html>
<body>
<script>
function openWindow() {
window.open("http://forums.devnetwork.net");
}

function shutdown() {
//some code to destruct thw window
}
openWindow();
setTimeout('shutdown()',4000)
</script>
</body>
</html>

Posted: Tue Jul 13, 2004 7:27 pm
by feyd
why do you not want to store the window reference?

Posted: Tue Jul 13, 2004 7:30 pm
by mcog_esteban
ok...i would like to close a ad window that pops from my web hosting provider.
it inserts some javascript on my scrips and i would like to close the opo window automatically.

Posted: Tue Jul 13, 2004 7:42 pm
by feyd
ahh... ok... don't know of a way to find a child window, however.. if you can figure out the name of the window they create, you can inject javascript into the window to close it.

Posted: Tue Jul 13, 2004 7:45 pm
by mcog_esteban
yes ..that's easy.
the problem is that they don't give it a name.
if there was a name i could add some some javascript after the </html> tag

Posted: Tue Jul 13, 2004 7:47 pm
by feyd
lemme see one of these pages.

Posted: Tue Jul 13, 2004 7:51 pm
by mcog_esteban

Code: Select all

<html>	
<body bgcolor=#000000<SCRIPT LANGUAGE="JavaScript">
		<!-- Begin
		var expDays = 1/1440;var page = "http://www.larouco.com/nosexo.htm";		var windowprops = "width=800,height=600,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes"; 
 

function GetCookie (name) &#123;  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) &#123;    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
&#125;  
return null;
&#125;
 
function SetCookie (name, value) &#123;  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv&#1111;2] : null;  
var path = (argc > 3) ? argv&#1111;3] : null;  
var domain = (argc > 4) ? argv&#1111;4] : null;  
var secure = (argc > 5) ? argv&#1111;5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
&#125;
 
 
 
function DeleteCookie (name) &#123;  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
&#125;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
 
 
 
function amt()&#123;
var count = GetCookie('count')
if(count == null) &#123;
SetCookie('count','1')
return 1
&#125;
else &#123;
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
   &#125;
&#125;
 

function getCookieVal(offset) &#123;
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
&#125;
 
function redireccionar() &#123;
    setTimeout("location.href=page", 1000);
  &#125;
 
 
 

function modelesswin(url,mwidth,mheight)&#123; 
if (document.all&&window.print) //if ie5 
eval('window.showModelessDialog(url,"","help:1;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")') 
else 
eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")') 
&#125;
 
 
 
function checkCount() &#123;
var count = GetCookie('count');
if (count == null) &#123;
count=1;
SetCookie('count', count, exp);
modelesswin(page,800,600) ;
 
&#125;
else &#123;
count++;
SetCookie('count', count, exp);
 
   &#125;
&#125;
//  End -->
 checkCount();
</script>
<table border=0 width=100% height=100%>
<tr>
<td><img width=100% height=100% src="images/noe.jpg" alt="what we do in life,echoes in eternity">
</td>
</tr>
</table>
<br><br><center><font size=1>Pagina alojada en <a href="http://www.redservicio.com">Redservicio.com hosting gratis</a></font></center></body>
</html>

feyd | Added

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Jul 13, 2004 8:00 pm
by feyd
so your host injects all that javascript into the page? yikes..

looks like there's an easier way to get rid of it: set a cookie 'count' with a value greater than 1.

Posted: Tue Jul 13, 2004 8:05 pm
by mcog_esteban
yep..they inject it in every page.
i'll try you advice.
thanks

Posted: Tue Jul 13, 2004 8:11 pm
by feyd
my idea (cookie) works locally... once I fixed the minor issue in the code you posted.. :)