SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    quick js help need on calling a function with in html

    folks

    Code:
    <a name="fb_share" type="icon_link" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
    now i want to format the above url in the href like this
    Code:
    http://www.facebook.com/sharer.php?u=<url to share>
    now, url to share is retrived by calling GetID() js function.
    now how do i put function name with in the html

    i put like this but did not work
    Code:
    href="http://www.facebook.com/sharer.php?u=GetID()"
    pls help.

  2. #2
    SitePoint Wizard Blake Tallos's Avatar
    Join Date
    Jun 2008
    Location
    Cuyahoga Falls, Ohio.
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    function () {
        //do something
        //do something
    }
    Blake Tallos - Software Engineer for Sanctuary
    Software Studio, Inc. C# - Fanatic!
    http://www.sancsoft.com/


  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    nop blake anthoney,
    my question seems not clear right.

    assume this is my simple js function

    Code:
    <script language="JavaScript">
    function getShortURL() {
    	var getShortURLText="http://www.someurl.com";
    	return getShortURLText;
    }
    </script>
    assume above function is impliment like this

    Code:
    	<a href=”getShortURL()”>post to facebook</a>
    is this correct? it dont work for me

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a href="#" onclick="this.href=getShortURL()">post to facebok</a>
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    Code:
    <a href="#" onclick="this.href=getShortURL()">post to facebok</a>
    hai AutisticCuckoo
    that worked charm.
    now my problem is this

    from here i grab the code for a custom url
    http://www.facebook.com/facebook-widgets/share.php

    <a name="fb_share" type="icon_link" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

    this require a url encording
    http://www.facebook.com/sharer.php?u=<Url to share>&t=<Title of content>

    now my question is
    if i did like this, it will not work

    <script language="JavaScript">
    function getShortURL() {
    var getShortURLText=document.getElementById("shorten-url-div").innerHTML; //this returns the url which i wannt to share on fb.
    getShortURLText="http://www.facebook.com/sharer.php?u=" + getShortURLText; // formatting my url to fb style
    return getShortURLText;
    }
    </script>

    and calling this function below

    <a name="fb_share" type="icon_link" href="#" onclick="this.href=getShortURL()">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

    what is the problem?

  6. #6
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    folks, it seem i messed up with fb code. just tell me the bolded part is correct?

    <a name="fb_share" type="button_count" share_url="getShortURL()" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    share_url isn't a valid link attribute, you'll be wanting the onclick attribute instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    share_url isn't a valid link attribute, you'll be wanting the onclick attribute instead.
    hai pmw57,
    not its part of that facebook share code only for the custom url
    http://www.facebook.com/facebook-widgets/share.php

    edited : if you put a url in to the share_url attribute insted of my js function, sharing works clearn.

    i tried this and still not working

    <a name="fb_share" type="button_count" href="#" onclick="this.href=getShortURL()">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

  9. #9
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ok friends. i manage to solve this post to facebook with following code.

    Code:
    <a href="#" onclick="this.href=getShortURL()">post to facebok</a>
    Thank you all and specially AutisticCuckoo for this.href


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •