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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Link with two functions?

    Hey guys,

    Im trying to make the following work..

    I have this piece of code as a link:

    PHP Code:
    <a href="'.$_SERVER['PHP_SELF'].'?mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')).'">Download your File.</a
    and I have this piece of javascript:

    Code:
    <a href="#" onClick="javascript:initGateway(); return false;">Click here</a>
    I need to blend these to together into one single <a href=""> so that when you click the link, both functions will be activated.

    Your help would be much appreciated. So far I haven't been able to pull it off..

    I tried the following but without result :

    PHP Code:
    <a href="'.$_SERVER['PHP_SELF'].'?mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')).';initGateway(); return false;">Download your MP3 file.</a

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You can't just quote PHP in the middle of HTML, it needs to be enclosed in <?php and ?> tags. I think this is correct, technically,

    PHP Code:
    <a href="<?php echo $_SERVER['PHP_SELF'] . '?mp3=' 
        
    urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')); ?>
        onclick="initGateway();return false;">Download your MP3 file.</a>
    But it won't work: clicking the link will cause the href to be followed and the click event will never happen.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    just put the link in the onclick command

  • #4
    New to the CF scene
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Its not really a link, it calls a piece of javascript..

    I'll explain further what I try to accomplish..

    Basically,
    The visitor clicks on a download button to get their mp3 file and when they do, the page freezes and an offer from our sponsor will appear on the screen asking them if they are interested in the offer. If they are not interested, they can close it to download their file.
    The offer is triggered with a piece of javascript.
    The javascript itself is placed below the <body>

    This is the php part:

    PHP Code:
    <?php
             
    // On form submission...
             
    if ($_POST['submit'])
             {
                 
    // Print "please wait" message and preview image
                 
    echo '<div id="preview" style="display:block"><p>...Please wait while I try to convert:</p>';
                 echo 
    '<p><img src="http://img.youtube.com/vi/'.$converter->ExtractVideoId(trim($_POST['youtubeURL'])).'/1.jpg" alt="preview image" /></p>';
                 echo 
    '<p>'.$converter->ExtractSongTrackName(trim($_POST['youtubeURL']), 'url').'</p>';
                 echo 
    '<div id="progress-bar"><div id="progress">0%</div></div></div>';
                 
    flush();

                 
    // Main Program Execution
                 
    if ($converter->DownloadVideo(trim($_POST['youtubeURL'])))
                 {
                     echo (
    $converter->GenerateMP3($_POST['quality'])) ? '<p>Success!</p><p><a href="'.$_SERVER['PHP_SELF'].'?mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')).'">Download your File.</a></p>' '<p>Error generating File!</p>';
                 }
                 else
                 {
                     echo 
    '<p>Error downloading video!</p>';
                 }
             }
         
    ?>
    Understanding that I am dealing with two different worlds (server vs client) I'm not sure how to go about this one..
    Last edited by xeondream; 08-02-2012 at 12:48 AM.

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    What does initgateway do? can it trigger the other script from within itself?

  • #6
    New to the CF scene
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    "initgateway" is supposed to trigger this script (

    PHP Code:
      <script type="text/javascript">var gwloaded false;</script>
      <script src="URL" type="text/javascript"></script>
      <script type="text/javascript">if (gwloaded==false){window.location = "#";}</script>
      <noscript><meta http-equiv="refresh" content="0;url=URL" /></noscript> 
    *offtopic, I took the actual links out for security reasons but this is the javascript.)

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    That is three separate scripts, none of which mention "initgateway"

    *offtopic 'noscript' is deprecated, as is the use of 'javascript:'.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #8
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    i'd modify your popup script to get the file when they close it


  •  

    Posting Permissions

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