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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Is there such a script ?

    Hi,

    I have been searching your scripts to solve a particular problem that I have but have not found the solution. Indeed it may not be possible.

    The Problem
    I have a site with a number of static pages and on those pages are links to txt and pdf documents. Currently when a visitor clicks the link it starts the download as usual. Instead I would prefer that when the user clicks the link to the document they are shown a confirmation screen with a possible advert or message that once they OK then downloads the link.

    Is this possible using a script?

    Thanks in advance.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,073
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Take a look at the JS 'confirm' statement.
    See: http://www.exforsys.com/tutorials/ja...nfirm-box.html

  • #3
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    This is almost what I need. Except that I need to be able to display HTML in the dialogue box.

  • #4
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I am bumping this again. Still really need an answer to this if possible.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by paz View Post
    This is almost what I need. Except that I need to be able to display HTML in the dialogue box.
    You can't. You would have to create your own modal dialogue box for this.

    You could of course display a different pre-defined message in the confirm box depending on which link was clicked.

  • #6
    New Coder 4B/75/73/41/'s Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    1
    Thanked 3 Times in 3 Posts
    So you want HTML tags to be visible in a pop up message box?

  • #7
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post
    This should point you in the right direction...
    Code:
    <html>
    	<script type="text/javascript">
    		function confirm_download(element){
    			file = element.href;
    			//display popup with confirm button calling the download_file() function
    			//make sure to pass the filename along
    			popup(file);
    		}
    		function popup(file){
    			//display popup
    			download_file(file);
    		}
    		function download_file(file){
    			window.location = file;
    		}
    	</script>
    	<a href="document.pdf" onclick="confirm_download(this)" >Click Here</a>
    </html>

  • Users who have thanked paintingtheweb for this post:

    paz (11-11-2008)

  • #8
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Thumbs up

    Many many thanks 'paintingtheweb'. This pointed me towards the following code which is perfect for my application and excatly what I was after.

    Script
    <SCRIPT LANGUAGE="JavaScript">
    function NewWindow() {
    win2=window.open("http://www.yourwebsite.com/popup.html","NewWindow","toolbar=no,directories=no,menubar=no,scrollbars=no,width=320,height=280");
    }
    </SCRIPT>


    Calling it
    onclick='NewWindow();'>

    This allowed me to pop up a page/popup/message for every PDF clicked on. Excellent.

  • #9
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have an additional question for you based on this script.

    Is there a way to universally call a NewWindow() without having to add the calling code to every download link on the page.

    In other words, tell the page to always display a NewWindow() whenever a user clicks on ANY *.pdf link or any *.exe link. This would prevent a lot of additional code on pages that contain a large quantity of pdf and exe links.

    If there was it would be very nice, any ideas ?

  • #10
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Example</title>
    <script type="text/javascript">
    // <![CDATA[
    
    function changeEmUp()
    	{
    	var all_anchors = document.getElementsByTagName("a");
    	var set_href = function(a_element,to)
    		{
    		if (a_element.setAttribute) a_element.setAttribute("href",to);
    		else a_element.href = to;
    		}
    	var get_href = function(a_element)
    		{
    		return a_element.getAttribute ? a_element.getAttribute("href") : a_element.href || false;
    		}
    	for (var i=0;i<all_anchors.length;i++)
    		{
    		if(get_href(all_anchors[i])) set_href(all_anchors[i],"javascript:NewWindow('"+get_href(all_anchors[i])+"')");
    		}
    	}
    
    // ]]>
    </script>
    </head>
    <body onload="changeEmUp()">
    
    <a href="http://www.google.com">Google</a><br />
    <a href="http://www.yahoo.com">Yahoo</a>
    
    </body>
    </html>
    Actually this function is a little better, just because it follows the href=# onclick=function pattern:
    Code:
    function changeEmUp()
    	{
    	var all_anchors = document.getElementsByTagName("a");
    	var set_href = function(a_element,to)
    		{
    		if (a_element.setAttribute) a_element.setAttribute("href",to);
    		else a_element.href = to;
    		}
    	var get_href = function(a_element)
    		{
    		return a_element.getAttribute ? a_element.getAttribute("href") : a_element.href || false;
    		}
    	for (var i=0;i<all_anchors.length;i++)
    		{
    		if (get_href(all_anchors[i]))
    			{
    			all_anchors[i].goto = get_href(all_anchors[i]);
    			set_href(all_anchors[i],"#");
    			all_anchors[i].onclick = function()
    				{
    				NewWindow(this.goto);
    				return false;
    				}
    			}
    		}
    	}
    Last edited by itsallkizza; 11-11-2008 at 07:41 PM. Reason: modification
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • Users who have thanked itsallkizza for this post:

    paz (11-12-2008)

  • #11
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    This is great stuff, I appreciate this and am learning a lot here.

    itsallkizza, I have used the second function and it works well. The only problem is that it workes no matter what I click on. If I only wanted this to be called when I click on a PDF or EXE or some other file link. Could this be done ?

    Thanks again for all the great advice.

  • #12
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Code:
    function changeEmUp()
    	{
    	var all_anchors = document.getElementsByTagName("a");
    	var set_href = function(a_element,to)
    		{
    		if (a_element.setAttribute) a_element.setAttribute("href",to);
    		else a_element.href = to;
    		}
    	var get_href = function(a_element)
    		{
    		return a_element.getAttribute ? a_element.getAttribute("href") : a_element.href || false;
    		}
    	for (var i=0;i<all_anchors.length;i++)
    		{
    		if (get_href(all_anchors[i]))
    			{
    			all_anchors[i].goto = get_href(all_anchors[i]);
    			if (all_anchors[i].goto.indexOf("exe") != -1 || all_anchors[i].goto.indexOf("pdf") != -1)
    				{
    				set_href(all_anchors[i],"#");
    				all_anchors[i].onclick = function()
    					{
    					NewWindow(this.goto);
    					return false;
    					}
    				}
    			}
    		}
    	}
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • Users who have thanked itsallkizza for this post:

    paz (11-14-2008)

  • #13
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you thank you thank you.

    This little bit of code has now transformed my approach to the links on my site and also made me think differently about my own code.

    Cheers
    Paul.

  • #14
    paz
    paz is offline
    New Coder
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    itsallkizza,

    This code does not seem to work. It loads the popup when I click to download a ZIP or PDF, however the download does not start. Can you check this for me.

    Thanks
    Paul.

  • #15
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Thanks for your email. Always feel free to ask me questions via e-mail, but I'm going to respond here on the forum so anyone else who has a similar problem can see what we're up to

    If I understand your needs correctly, then you should create a server-side intermediary something like this...
    confirm_download.php:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Confirm Download</title>
    <style type="text/css">
    </style>
    <script type="text/javascript">
    // <![CDATA[
    function back()
    	{
    	if (history && history.go) history.go(-1);
    	return false;
    	}
    // ]]>
    </script>
    </head>
    <body>
    
    <?php
    $furl = $_GET["furl"] ? $_GET["furl"] : null;
    if ($furl)
    	{
    	?>
    
    	<!-- You can put as much html here as you want and style it normally with CSS to make a pretty confirmation page. -->
    	<h2>Are you sure you want to download <?php echo($furl) ?>?</h2>
    	<a href="<?php echo($furl) ?>">Yes</a> <a href="#" onclick="return back()">No</a>
    
    	<?php
    	}
    else echo("Sorry, you have been misdirected to this page.");
    ?>
    
    </body>
    </html>
    Then change your NewWindow function:
    Code:
    function NewWindow(file_url)
    	{
    	win2 = window.open("confirm_download.php?furl="+file_url,"NewWindow","toolbar=no,directories=no,menubar=no,scrollbars=no,width=320,height=280");
    	}
    And you should be good to go
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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