Skip to content

Instantly share code, notes, and snippets.

@kixxauth
Created July 10, 2013 19:10
Show Gist options
  • Save kixxauth/5969235 to your computer and use it in GitHub Desktop.
Save kixxauth/5969235 to your computer and use it in GitHub Desktop.
Link to Twitter App from iBooks Widget
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container">
<h1>Link to an External iOS App</h1>
<section class="static-tweet">
<h3 class="header">
Post a tweet with a static link.
</h3>
<p class="content">
<a href="twitter://post?message=This%20tweet%20was%20posted%20from%20your%20iBook">Post a tweet to the Twitter App</a>
</p>
</section>
<section class="dynamic-tweet">
<h3 class="header">
Post a tweet with dynamic content.
</h3>
<p class="content">
<label for="twitter-post">Create a Tweet:</label>
<textarea id="twitter-post"></textarea>
</p>
<p class="content">
<button onclick="postToTwitter()">Post it!</button>
</p>
</section>
</div>
<script type="text/javascript" src="js/script.js" charset="utf-8"></script>
</body>
</html>
// This function is invoked when the button is pushed.
function postToTwitter () {
// Get the tweet content from the HTML text area.
var tweet = document.getElementById('twitter-post').value;
// Encode the tweet content to send it to the Twitter app
// (puts in the '%' symbols where needed).
tweet = encodeURI(tweet);
// Create the link.
var url = 'twitter://post?message=' + tweet;
// Open the link.
window.location.href = url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment