如何通过JavaScript代码段显示iframe? [英] How to display iframe by a Javascript snippet?
问题描述
我已经看到一些在线的小部件,使用户可以在自己的页面中添加一个简短的Javascript代码段,当执行时,它会显示一个Iframe,如下例所示。
I have seen some widgets online that gives the user the possibility of including a short Javascript snippet in their own page, which when executed displays an Iframe, like in the following example.
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=APP_ID&xfbml=1"></script><fb:facepile></fb:facepile>
我该怎么做 - 在我的服务器上有一个JavaScript,当在远程服务器,写出一个iframe或将内容加载到他们的网页?
How can I do this by myself - have a javascript on my server, that when called on a remote server, writes out an iframe or loads content into their page?
推荐答案
我想你可能有这样的工作有点混合向上。它的工作方式是:
1.用户从您的域/服务器请求页面,页面被提供。
2.用户机器上的客户端Web浏览器解释所述页面,如果脚本块包含对某个其他位置的js文件的引用,则会提取所述js文件。
3. Javascript由客户端浏览器处理。
I think you may have how this is working a bit mixed up. The way it's working is this: 1. User requests page from your domain/server, page is served. 2. Client web browser on users machine interprets said page, if a script block includes a reference to a js file at some other location then said js file is fetched. 3. Javascript is processed by the clients browser.
所以真正需要的是在服务器上的JS文件(简单的旧ASCII)一些document.write()调用来添加你想要添加的代码,例如:
So really all you need is a JS file (plain old ASCII) on the server and have it do some document.write() calls to add the code you want it to add, for example:
转到 http://www.shaunhusain.com/TestIFrameViaJS
三个文件涉及
索引。 html
anotherpage.html
testIFrame.js
three files there involved index.html anotherpage.html testIFrame.js
让我知道如果它不行,或者我采取错误的方向,重新寻找?
let me know if it doesn't work out or I took a wrong direction for what you're looking for?
Shaun
这篇关于如何通过JavaScript代码段显示iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!