Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    click link - open site in _blank - close page..

    Hi all

    i have searched for help on this, i hope i havent missed the answer - here goes..

    is it possible to have a link that when you click on opens the link in a new browser window and closes the orginal window

    i know:

    <a href="../page-name.html" target="_blank">link</a>

    will open the url in a blank window - but how to close the first window at the same time?

    thanks for any help
    as ever
    keen to learn..

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    onClick="javascript:window.close"

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi

    thanks for the help

    so how do i combine the js to do both open the link in a new browser window and close the first browser?

    thanks again
    keen to learn..

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <a href="../page-name.html" target="_blank" onClick="javascript:window.close();">link</a>

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Flic
    <a href="../page-name.html" target="_blank" onClick="javascript:window.close();">link</a>
    Firstly, that's unlikely to work because most browsers disallow* the use of js to close windows which weren't created using js.
    (* I recall seeing someone post a js method to 'trick' into allowing it FF, but I can't recall it. There is also a method to trick IE6 into allowing it, but I think that vulnerability was closed down in either an IE6 point upgrade or possibly the SP2 XP upgrade.
    You might find it by searching here or Googling around.)

    Secondly…
    onClick="javascript:window.…

    The 'on' events are already capable of handling js directly, so you really don't need to invoke the javascript protocol as well.

    i.e.
    Code:
    <a href="../page-name.html" target="_blank" onClick="window.close();">link</a>
    …though, like I said, it won't work without the tricks; and even then, it's still unlikely to work reliably x-browser.
    Personally, unless this is for an intranet situation, I wouldn't even attempt to close the main window.
    You risk upsetting a user's browser session and they may thank you for it by leaving your site never to return.
    I've never heard of someone leaving a site never to return because they didn't close the main window.

    Open a new window if you feel that you must, but try to avoid messing about with the user's main window.
    Last edited by Bill Posters; 05-26-2006 at 02:11 PM.

  • #6
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi flic / bill

    thanks for the posts - its a strange request i know and asked for a pretty unique reason.

    i will have to think of another way to make this work.

    thanks for the time.

    as ever
    keen to learn..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •