SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot get_dave's Avatar
    Join Date
    Nov 2006
    Location
    England, UK
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Alert before redirect

    Hi guys. I hope one of you can help me out. Two objectives:

    1) I'm wanting to use javascript to generate an alert box which fires when a user clicks on a link. This box should alert the user that a new window will now open which will contain a Microsoft Word document. I want this link to open in a new window.

    2) I'm wanting to use javascript to generate a confirm box which fires when a user clicks on a link. This box should alert the user that if they procede a new window will open which will contain a Microsoft Word document. I want to give them the option of clicking "ok" to travel to the link, or "cancel" to remain where they are. Again the link should open in a new window.

    Can anyone suggest a simple solution?

    Many thanks for taking the time to read this,

    Dave Smith
    I'm looking for a link exchange.
    contact me or head to:
    http://www.aheadcreative.co.uk

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try something like this
    Code:
    <script type="text/javascript">
    function goif(what){
    var doc=confirm("This will open Word document");
    if(doc){document.location.href=what.href}
    else{return false;}
    }
    function checkLnk(){
    var lnk=document.getElementsByTagName('a');
    for(var i=0;i<lnk.length;i++){
    if(lnk[i].href.indexOf('.doc')!=-1){
    lnk[i].onclick=function(){
    goif(this);return false;
    }
    }
    }
    }
    window.onload=checkLnk
    </script>
    </head>
    <body>
    <a href="#">test #</a>
    <a href="x.html">test html</a>
    <a href="x.doc">test word .doc</a>
    <a href="x.txt">test txt</a>
    </body>
    </html>

  3. #3
    SitePoint Enthusiast tuxidomasx's Avatar
    Join Date
    Feb 2007
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the html:
    HTML Code:
    <a href='javascript:void(0);' onClick='javascript: 
    if (confirm("This will open a word doc in a new window. Proceed?")) window.open("http://yoursite.com/document.doc")' >Click me!</a>
    i make it rain on them hoes


Bookmarks

Posting Permissions

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