Skip to content

Instantly share code, notes, and snippets.

<a href="#addurl" data-icon="plus">Add URL</a>
<div data-role="page" id="addurl">
<div data-role="header" data-theme="b" data-position="fixed">
<a href="#home" data-icon="home" data-iconpos="notext">Home</a>
<h1>Add URL</h1>
<a href="#home" data-icon="arrow-l" data-rel="back">Back</a>
</div>
<div data-role="content">
<form action="#home" method="POST" name="addurl" id="addurl">
<div data-role="fieldcontain">
<label for="url">URL:</label>
// Refresh home page using dynamic url list.
$(document).ready(function() {
$.mobile.changePage("#home");
});
// Listen for any attempts to call changePage().
$(document).bind( "pagebeforechange", function(e, data) {
// We only want to handle changePage() calls where the caller is asking us to load a page by URL.
if (typeof data.toPage === "string") {
// We only want to handle a subset of URLs.
var u = $.mobile.path.parseUrl(data.toPage);
var home = /^#home/;
var qrcode = /^#qrcode/;
if (u.hash.search(home) !== -1) {
// Display a list of URLs.
// Display a list of urls you want to share.
function showUrlList(urlObj, options) {
// Get list of urls
var myUrls = getMyUrls();
// Get the page we are going to write our content into.
var $page = $("#home");
// Get the content area element for the page.
var $content = $page.children(":jqmData(role=content)");
// Retrieve a list of URLs from the local storage.
// Use defaults if storage has not been initialized yet.
// URLs are serialized using JSON for storage.
function getMyUrls() {
var myUrls;
var storedUrls = localStorage.getItem("myUrls");
if (storedUrls) {
// Deserialize URLs
myUrls = JSON.parse(storedUrls);
}
img.center {
display: block;
margin-left: auto;
margin-right: auto;
}
<!DOCTYPE html>
<html>
<head>
<title>Share QR</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="shareqr2.2.css" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="shareqr2.2.js"></script>
// Listen for any attempts to call changePage().
$(document).bind("pagebeforechange", function(e, data) {
// We only want to handle changePage() calls where the caller is asking to load a page by URL.
if (typeof data.toPage === "string") {
// We only want to handle #qrcode url.
var u = $.mobile.path.parseUrl(data.toPage);
var qrcode = /^#qrcode/;
if (u.hash.search(qrcode) !== -1) {
// Display QR code for the selected URL.
showQRCode(u, data.options);
<div data-role="content">
<ul data-role="listview">
<li><a href="#qrcode?url=http%3A%2F%2Fctoinsights.wordpress.com">ctoinsights.wordpress.com</a></li>
<li><a href="#qrcode?url=http%3A%2F%2Fwww.book-current.com">www.book-current.com</a></li>
</ul>
</div>