Jump to content

window.close() doesn't anymore...


thesoundsmith
 Share

Recommended Posts

The "Close" button in the player used to close the page, when I changed the DOCTYPE to HTML5 I now get a message that "/window.close() does not exist. Where does the slash come from, and how do I fix it? I tried javascript:window.close() with no change.

<a id="btn3" class="button3" title="Close DashRadio" href="window.close();"></a>

The page is at http://www.thesounds...com/radiopg.htm If you open it, a song will play, press the Pause button or player display to shut it up (the page is only called when you WISH to hear the music...) Thanks.

Edited by The Soundsmith
Link to comment
Share on other sites

What's the better way? I replaced the code with yours and it works now - but that was the original code, and it had failed - must have had a typo. But if there is a more modern method, I'd love to know it. Thanks.BTW IE still complains - the window closes, but complains. If you know the way around that issue, that would be an even greater help.

Edited by The Soundsmith
Link to comment
Share on other sites

Again, I must have made a typo originally. AFAIK, there are 4 variations - using href= vs onclick= and with or without javascript;, all with window.close(). When I began this thread, I had already tried all four; none of the options worked, I do not know why. After Deirdre's Dad's post, I redid the link and it worked. He called it old-school, is onclick any newer? It also worked this time, I'm beginning to suspect I was using a close{} instead of (), it's a bit hard to see the difference.But all cases in IE generate an additional alert before allowing you to close. I am asking for a workaround, if any.

Link to comment
Share on other sites

What you're doing works, and I really don't want to mess with that. The more modern approach is more a philosophical choice than anything. Part of it says that elements have a purpose and shouldn't be manipulated into a different purpose. Like not using tables for layout. You've probably heard that. So semantically speaking, an <a> element should only ever be an anchor; it shouldn't just be a button to trigger some JavaScript. Another principle says we should isolate structure, style, and behavior from each other as much as possible. So we no longer have <font> tags like we used to, and CSS has taken over the role of old in-tag attributes like bgcolor and so on. Same with JavaScript. Modern developers don't put it in tags anymore. They keep all the scripting separate. I posted some stuff for a guy earlier today that shows one way that can look. Most of that won't apply to your situation, except for the way that the click handlers are attached to the buttons (which could just as easily be images or text spans). And to be completely honest (bless me, Father) the technique I show there isn't completely modern, since I'm not using the W3C recommended addEventListener method. As usual, IE is the reason. addEventListener doesn't work for IE versions before 9. element.onclick works everywhere, so it remains my personal preference. A lot of developers get past the seeming impropriety by using jQuery, which matches the technique to the browser version. As I said, it's not my place to upset a page that works and apparently validates. But you asked, and I'm a teacher by trade, so . . . :)

  • Like 2
Link to comment
Share on other sites

Thanks, DD. Yes that IS exactly what I asked for, I appreciate the philosophical underpinnings, it helps figure how to approach new coding. These days I take a LONG hiatus between programming bouts (last significant update was 2008), and forget everything I used to sort-of know. So my newer code is mostly cut-and-paste, throwing stuff at a page till it sticks, and cleaning up later... But I do like to see what's coming down the pike so I can minimize re-coding when old instructions are being phased out. (And I also love to learn, slow as I am.) So thanks again for the help.

Edited by The Soundsmith
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...