使用 iFrame,我网站上的某人可以访问他们的 Facebook 帐户,显示他们的相册列表,然后显示所选相册中的照片。
目前,当用户单击照片时,我会显示一个对话框,其中显示照片的路径。
以上所有内容都完美运行。
我的下一步是将照片的路径信息传递回我的网页,但我不确定如何执行此操作,因为我想要将数据传递到的对象位于 iFrame 之外,因此 Facebook 不知道该对象。我尝试通过我的网站上包含 iFrame 的 DOM 引用它来自上而下...
parent.client.document.getElementById("FBPhoto").setValue(photoReference);
...但这没有用。
在我的网站上将参数传递给 PHP 脚本将不起作用,因为我不想刷新网站上的页面(因为这会导致用户丢失数据)。
Using an iFrame, someone on my website can access their Facebook account, display a list of their photo albums, and then display photos from selected albums.
At the moment, when the user clicks a photo, I display a dialog box that shows the photo's path.
All of the above works perfectly.
My next step is to pass the photo's path info back to my web page, but I'm not sure how to do that because the object, to which I want to pass the data, is outside of the iFrame and therefore unknown to Facebook. I tried going top-down by referencing it through the DOM that contains the iFrame on my website...
parent.client.document.getElementById("FBPhoto").setValue(photoReference);
...but that didn't work.
Passing the argument to a PHP script, on my site, won't work because I don't want to fresh the page on my site (since that would cause the user to lose data).
发布评论
评论(2)
从你提供的内容来看,你的 JS 可能是错误的。
做这样的事情可能会得到你需要的值:
然后你需要将它分配给某些东西:
注意:
window.frames["iframe-name"].document.getElementById("FBPhoto")
将返回名为#FBPhoto
的 DOM 元素,因此将是一大块 HTML。您的setValue()
方法可能不希望出现这种情况。我建议您尝试在 Firefox 中使用 Firebug,它允许您将
photoReference
的值转储到控制台以查看返回的内容。From what you've provided it looks like your JS might be wrong.
Doing something like this might get you the value you need:
Then you need to assign it to something:
Note:
window.frames["iframe-name"].document.getElementById("FBPhoto")
will return the DOM element called#FBPhoto
and will therefore be a big chunk of HTML. YoursetValue()
method might not be expecting that.I suggest you try running your script in Firefox with Firebug installed, which will allow you to dump the value of
photoReference
to the console to see what you're getting back.Doy...我意识到,由于 Facebook 连接在专用的 iFrame 中运行,因此重定向该框架不会有问题,因为无论如何都没有理由让它保持打开状态。
对于任何感兴趣的人,这就是我所做的...
PHP(在index.php 内部)显示相册照片。
PHP 还使用 href 标签包围每个 img 框架。
该链接指向一个 PHP 文件(在我的网站上),并包含一个带有大版本照片位置的参数(因为我的应用程序显示缩略图)。类似于: "< a href="pathToMySite/get-photo.php?photopath=facebook's path ">
当用户单击所需的照片时,其相应的链接将调用 get-photo.php(在我的网站上)并传递照片的路径。
当
get-photo.php 然后将对我的网站的主 JS 文件的引用插入到文档头中,并将脚本插入到 HTML 文档的正文中。
该脚本调用 JS 获取照片函数,并传递从运行 Facebook 应用程序的嵌入式 iFrame 接收的路径参数。
JS 函数关闭 iFrame(因为那时我已经不再使用 Facebook)并从 Facebook 获取照片。
Doy... I realized that since the Facebook connection was running in a dedicated iFrame, it wouldn't be a problem to re-direct that frame because there was no reason to leave it open anyhow.
For anyone interested, here's what I did...
The PHP (inside of index.php) displays the album photos.
The PHP also surrounds each img frame with href tags.
The link points to a PHP file (on my website) and includes an argument with the location of the large version of the photo (since my app is displaying thumbnails). Something like: "< a href="pathToMySite/get-photo.php?photopath=facebook's path ">
When the user clicks on the desired photo, its respective link calls get-photo.php (on my site) and passes the path for the photo.
get-photo.php then inserts a reference to my website's main JS file into the document head, and inserts a script into the body of the HTML document.
The script calls a JS fetch-photo function, and passes the path argument that it received from the embedded iFrame that was running the Facebook app.
The JS function closes the iFrame (since I'm done with Facebook at that point) and grabs the photo from Facebook.