Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

php - how to call javascript of facebook api for sending dynamic values in order to post in wall

I have a parent page where I am submiting a form and calling two funcions on_click of the submit button. One function from the same page and another from child page.

I am wondering how to call a Javascript funcion on the parent page from the child page to post on a Facebook wall. This is my application.

My parent.php:

<form action="child.php" method="post">
   <input type="text" value="$result" name="codebox">
   <input type="submit" onclick="funcion codeload();function postToFeed();"/>
</form>

My child.php:

 <body> 
  <?PHP
          $son=$_REQUEST['codebox'];
          session_start();
          $_SESSION['sony'] =$son;
          $ashutosh=$_SESSION['sony'] ;
          $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?                 
                url=http://www.ebhasin.com/approval/files/main.php?a=$ashutosh");
          $desc='Place here description what you want';
  ?>
<div id='fb-root'></div> 
<script src='http://connect.facebook.net/en_US/all.js'></script>

<p id='msg'></p>    

<script>

  FB.init({appId: "313877282043416", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
    var obj = {
      method: 'feed',
       link: '<?PHP echo $tinyurl?>',
            picture: 'http://www.dogoscanarios.com/en/themes/dogotheme/images/icon_dot_cat.gif',
      name: 'Drum Precussion',
    caption: ' I just created a new Drum Loop using Drum Beats Pro! Come listen to it!',
      description: '.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
  }

</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well if lets say the parent window opens a child popup window, then do as following

EDIT :

Your parent page, parent.php

 <script>
var Popup;
function popUp()
{
    Popup = window.open("child.php", "bpPopup", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=420,height=300,left = 490,top = 262');
    Popup.focus();
}
</script>
<a href="javascript:void(0)" onclick="popUp();">Open child window</a><br />
<a href="javascript:void(0)" onclick="Popup.postToFeed();">Call child window function</a>

First link opens popup window, second link calls the function postToFeed() in popup window from parent.

Your child popup window, child.php

<script>
function postToFeed(){
    alert("Popup function called by parent window");
}
</script>

This function in popup window is called after you click the link in parent window.

Hope This helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...