JavaScript and client side scripting.
Moderator: General Moderators
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 6:57 pm
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Jul 13, 2004 7:00 pm
<a href="javascript:window.close()">close window</a>
?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 7:01 pm
window.close() generally...
wow.. was I behind a ways on that one..
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 7:07 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 7:11 pm
the info is returned from window.open..
Code: Select all
var windowref = window.open("whatever");
windowref.close();
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 7:25 pm
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>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 7:27 pm
why do you not want to store the window reference?
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 7:30 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 7:42 pm
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.
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 7:45 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 7:47 pm
lemme see one of these pages.
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 7:51 pm
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) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argvї2] : null;
var path = (argc > 3) ? argvї3] : null;
var domain = (argc > 4) ? argvї4] : null;
var secure = (argc > 5) ? argvї5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function redireccionar() {
setTimeout("location.href=page", 1000);
}
function modelesswin(url,mwidth,mheight){
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")')
}
function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
modelesswin(page,800,600) ;
}
else {
count++;
SetCookie('count', count, exp);
}
}
// 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]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 8:00 pm
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.
mcog_esteban
Forum Contributor
Posts: 127 Joined: Tue Dec 30, 2003 3:28 pm
Post
by mcog_esteban » Tue Jul 13, 2004 8:05 pm
yep..they inject it in every page.
i'll try you advice.
thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 8:11 pm
my idea (cookie) works locally... once I fixed the minor issue in the code you posted..