Angular, AWS und Symfony Freelancer

Mobile Multi Share Implementation mit jQuery Mobile

Mit dem passendem HTML lässt sich so sehr komfortabel ein Share-Alternative aufbauen für mobile Anwendungen um Platz zu sparen (mit jQuery Mobile).

Dabei werden die Share Dienste in ein <select> Tag eigetragen und per Javascript einzeln gehandelt. Das Ergebnis sieht auf Android-Phones so aus:

20121127-154143.jpg

HTML:

            <label for="select-choice-share">Share</label>
            <select name="select-choice-share" id="select-choice-share" data-icon="forward" data-mini="true" data-iconpos="left" onchange="handleSocialShare()">
                <option value="no">Share it</option>
                <option value="facebook">Post this on Facebook</option>
                <option value="twitter">Tweet this</option>
                <option value="email">Email this</option>
            </select>

Javascript:

function handleSocialShare()
{
    $('#select-choice-share option:selected').each(function()
    {
        text = "Flash vs HTML5 Trendanalyse";
        url ="http://www.sebastianviereck.de/flash-html5-trendanalyse/#.ULTEkYb9n2A";

        shareService = $(this).val()
        switch (shareService) {
            case "facebook":
                shareFacebookLike(url);
                break;
            case "twitter":
                shareTwitter(url, text);
                break;
            case "email":
                shareEmail(url, text);
                break;
            default:

        }
    });
}

Auf Android Handy werden diese Events wie folgt ausgeführt:

20121127-154219.jpg
Mailto Befehl fragt nach Email Client
20121127-154227.jpg
Facebook Link startet Facebook Seite

Facebook Like mit Javascript triggern

function shareFacebookLike(url)
{
    window.location="http://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(url);
}

Twitter Tweet mit Javascript triggern

function shareTwitter(url, text)
{
    window.location = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(text) + "&url=" + encodeURIComponent(url);
}

Email schreiben mit Javascript triggern

function shareEmail(subject, body)
{
    window.location = "mailto:&subject=" + subject + "&body=" + body;
}

Veröffentlicht

in

,

von

Schlagwörter:

Kommentare

5 Kommentare zu „Mobile Multi Share Implementation mit jQuery Mobile“

  1. Avatar von Karl Paschke
    Karl Paschke

    Danke, dass hatte ich gesucht!

  2. Avatar von netalex
    netalex

    Hi, tanks for the explanation. a question: how do you deal with application life cycle? Sayng, this line “ window.location=“http://www.facebook.com/sharer/sharer.php?u=“ + encodeURIComponent(url);“ opens a new browser window, rught? So it is’nt very likely that in the meantime user shares link, the app will close?
    Have you seen that Apache Cordova Plugin who deals whit this issue?
    http://tech.sarathdr.com/featured/social-share-plugin-for-android-cordova-2-2-0-email-sms-facebook-twitter-share/

  3. Avatar von MareB
    MareB

    Hi, thnx for posting this. I am wondering how to use facebook function properly? I does not insert anything into the posting window. Any suggestions?

  4. Avatar von MareB
    MareB

    Hey guys, I get the same problem as that guy stated here:
    http://stackoverflow.com/questions/16990574/javascript-or-php-posting-on-facebook
    Any solutions? Thank you!

  5. Avatar von shad
    shad

    Thanks. lightweight & easily adjustable with css!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert