Попробуйте это.
Сценарий:
<script language="javascript" type="text/javascript">
<!--
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser is very old!");
}
}
}
//Browser Support Code
function ajaxGetTiny(){
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDisplayTiny');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var long_url = document.getElementById('long_url').value;
var queryString = "?long_url=" + long_url;
ajaxRequest.open("GET", "getTiny.php" + queryString, true);
ajaxRequest.send(null);
}
function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}
//-->
</script>
Теперь форма:
<form name='myForm'>
<input name="long_url" type="text" class="main" size="90">
<br>
<input type='button' class="Buttons" onclick='ajaxGetTiny();' value='GET TINY' />
</form>
Теперь вспомогательный файл:
<?
//gets the data from a URL
function get_tiny_url($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
//test it out!
$new_url = get_tiny_url($_GET['long_url']);
?>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<table width="100%" border="0" class="main">
<tr>
<td width="5%" align="left" valign="middle"><strong>longURL:</strong></td>
<td width="95%" valign="middle" class="ArticleBody"><? echo $_GET['long_url']; ?></td>
</tr>
<tr>
<td align="left" valign="middle"><strong>tinyURL:</strong></td>
<td valign="middle" class="ArticleBody"><SPAN ID="copytext"><? echo $new_url; ?></SPAN>
<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA><br>
<BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>
</td>
</tr>
</table>