...

View Full Version : Link with two functions?



xeondream
08-01-2012, 10:24 PM
Hey guys,

Im trying to make the following work..

I have this piece of code as a link:


<a href="'.$_SERVER['PHP_SELF'].'?mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')).'">Download your File.</a>

and I have this piece of javascript:


<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 :


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

AndrewGSW
08-01-2012, 11:03 PM
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,


<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.

Arcticwarrio
08-01-2012, 11:25 PM
just put the link in the onclick command

xeondream
08-01-2012, 11:45 PM
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
// 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..

Arcticwarrio
08-02-2012, 12:07 AM
What does initgateway do? can it trigger the other script from within itself?

xeondream
08-02-2012, 12:16 AM
"initgateway" is supposed to trigger this script (


<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.)

AndrewGSW
08-02-2012, 01:06 AM
That is three separate scripts, none of which mention "initgateway" :confused:

*offtopic 'noscript' is deprecated, as is the use of 'javascript:'.

Arcticwarrio
08-02-2012, 10:52 AM
i'd modify your popup script to get the file when they close it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum