window.close...

  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

ok im having problems closing a window its the index page of my site and i have it redirecting to another page (my home page) ive only done this for a short time until i make a 1024x768 page so at the moment i have just shortcutted by making a new page centering it keeping it at 800x600 and made it so it is unresizable i know i shud make 2 pages and then make it so it loads the right one onload but i havent got the time lol its at http://www.onspring.co.uk hopefully u can get to it this time cos last time u cudnt for some reason
thanx for any help
d7
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

oops i didnt ask the question i wanted to ask lol i meant.... i need it to close without the user clicking the ok in the box i know its possible but ive spent time playing around with it and what ive seen is that if u load it in javascript then u can close it without the message box comin up i just dont know how to make it so it doesnt bring up the message box
d7
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

put this as your link:
Code: [ Select ]
<a href="javascript:parent.close()">Close this window</a>

that should do it. :D
  • Steen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 343

Post 3+ Months Ago


No, that doesn't do it.
it still prompts the dialog box from Windows OS to warn that
this site is trying to close, do you want to allow such?

I've dealt with this before.

I'll have to look around but I recall it would only work properly
if you still had a console from that same domain still open in the background.

The DOM, Document Object Model is not being closed by the user,
the warning comes up because the code selected on the DOM is trying
to close it, thus it asks for user permission.

I foget how we dealt with this problem,
I'll have to check, I do believe we ended up popping
a console while keeping one in the background.

but then again, I would only want to put further effort into this,
if you still needed to resolve this problem.
  • Steen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 343

Post 3+ Months Ago

I wonder if you couldn't just null out the window.alert(string)
within the window.close event.
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

oh, i forgot about the "same domain" thing. thx for catching that steen.

No reply from him yet hmm...
  • Steen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 343

Post 3+ Months Ago

Apparently you can avoid the alert
if there is only one location in the window's history, so if you open a
child window and close it from within the child window, there is no
message.

It's a Microsoft Security thing!

This problem is not an issue when doing HTA's (applications)
as in:
Invoking the window.close method on an HTA closes the application without prompting the user because the HTA is trusted and follows a different security model.


but in the broswers, it's not the same.

http://msdn.microsoft.com/library/defau ... lose_0.asp


To this date, this is still a *peach* up issue.

I've read comments on flushing out the history before going
to a child window but I'll be damned it I can find a sample anywhere.

sorry ...
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

sorry flux i been away a while and forgot about this lol but yea steen is rite it dont work but i have seen examples of it working but only on click and not onload security thing how annoying lol
d7
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

well after all that looking around at the time i suddnely coem across it earlier while looking for something else but here it is the code that stops it from prompting u asking if u want to close the window so its what uve all been waiting for lol..
Code: [ Select ]
window.opener = null
window.close()
return false
  1. window.opener = null
  2. window.close()
  3. return false

so ppl put this after ur window.open() statement or if u want to just close the window wen u click it then its..
Code: [ Select ]
<a href="#" onclick="window.opener=null; window.close(); return false">thelinkbuttonorwhatever</a>


ok ppl i hope that helped y'all it definitely helped me lol
d7
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Oh very nice glad to see you figured it out and maybe it will help many others now :D
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

oh that's fantastic! thanks dreamer7...it will def help others. :D
  • Steen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 343

Post 3+ Months Ago


hahaha ...

yeah that 'null' thing works for a lot of things very well.

glad to see you managed, I know I had a hard time finding something,
yet knew it could be done.

I'd be interested in the whole code if you have it.

thanks,
  • Steen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 343

Post 3+ Months Ago


that works great.

thanks a ton,
I saved it and it's a keeper.
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

umm...isn't this the whole code?
Code: [ Select ]
<a href="#" onclick="window.opener=null; window.close(); return false">thelinkbuttonorwhatever</a>
:?: :?:
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

erm to close a window by clicking on it yes why u found a problem???? :shock: :(
  • Borrow -A- Geek
  • Professor
  • Professor
  • User avatar
  • Posts: 763
  • Loc: Dallas/Ft Worth, Texas

Post 3+ Months Ago

Cool thanks for the tip Dreamer, thats why this forum works, cuz we have so many people with a combined "brain".

i just donated 5 Participation points to you for that one! :-)
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

lol thanx gadget i knew i was gonna come in useful one day for something other than asking questions lol :D
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

great idea gadget! [i gotta remember these things ;)]

dreamer, I just gave you 5 also! :D
  • killercelery
  • Newbie
  • Newbie
  • killercelery
  • Posts: 13
  • Loc: Montréal, Québec

Post 3+ Months Ago

I'm not sure if the only problem is the version of IE (5.0) but your code won't work and it works great on IE6, can you please check your version and tell me??
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

Its true i've had a few people ask me why it doesn't work for them and i couldn't figure it out but i have IE 6 and it works for me but why wouldn't it work for IE 5??
d7
  • killercelery
  • Newbie
  • Newbie
  • killercelery
  • Posts: 13
  • Loc: Montréal, Québec

Post 3+ Months Ago

It seems to be IE5 fault. Not sure why, I don't have the technical information but it looks to be a security management problem.
  • trance
  • Newbie
  • Newbie
  • trance
  • Posts: 6

Post 3+ Months Ago

:lol: thanks for this one!
it really helped a lot!

more power to you guys!
  • mOrfer-
  • Born
  • Born
  • mOrfer-
  • Posts: 1

Post 3+ Months Ago

Great! ... if i add this code at the beginning of some php page I get fullscreenpage without parent!


PHP Code: [ Select ]
<?php if(!isset($_GET["newwin"])) { ?>
<script language="javascript">
var height = 50;
var width = 50;
var name = "winname";
var top = 0;
var left = 0;
 
newwin=window.open(document.location + "?newwin=true", name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
document.write('<a href="#" id="closeWin" onclick="window.opener=null; window.close(); return false">close</a>');
document.getElementById("closeWin").click();
 
</script>
<?php
exit;
} else { ?>
<script language="javascript">
   self.moveTo(0,0);
   self.resizeTo(screen.availWidth,screen.availHeight);
</script>
<?php
}
?>
  1. <?php if(!isset($_GET["newwin"])) { ?>
  2. <script language="javascript">
  3. var height = 50;
  4. var width = 50;
  5. var name = "winname";
  6. var top = 0;
  7. var left = 0;
  8.  
  9. newwin=window.open(document.location + "?newwin=true", name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
  10. document.write('<a href="#" id="closeWin" onclick="window.opener=null; window.close(); return false">close</a>');
  11. document.getElementById("closeWin").click();
  12.  
  13. </script>
  14. <?php
  15. exit;
  16. } else { ?>
  17. <script language="javascript">
  18.    self.moveTo(0,0);
  19.    self.resizeTo(screen.availWidth,screen.availHeight);
  20. </script>
  21. <?php
  22. }
  23. ?>
  • getvinay
  • Born
  • Born
  • getvinay
  • Posts: 1

Post 3+ Months Ago

i tried this script to close window without alert box.. it works great in IE but doesnot work in firefox.. so can u help me in that??

Post Information

  • Total Posts in this topic: 24 posts
  • Users browsing this forum: No registered users and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.