为用户生成 javascript 嵌入代码
我一直在试图弄清楚如何生成一段 javascript 代码,该代码允许网站用户将其复制并粘贴到自己的网站中,就像 google Adsense 和嵌入代码一样:
<– Begin Google Adsense code –>
<script type=”text/javascript”>
google_ad_client = “ad-client-code-goes-here”;
google_ad_slot = “ad-slot-code-goes-here”;
google_ad_width = 300;
google_ad_height = 250;
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>
<– End Google Adsense code –>
我很乐意创建类似的东西。我正在做一个类似的项目服务,希望用户上传图像(广告),然后让他们点击“生成广告代码”链接,然后他们将收到一段类似的代码片段,如上面的代码片段,他们可以在其中粘贴到他们的网站。
对此的任何帮助都会很棒,谢谢。
I have been trying to figure out how I can generate a piece of javascript code that will allow site users to copy and paste it into their own sites, much like google Adsense and there embed code:
<– Begin Google Adsense code –>
<script type=”text/javascript”>
google_ad_client = “ad-client-code-goes-here”;
google_ad_slot = “ad-slot-code-goes-here”;
google_ad_width = 300;
google_ad_height = 250;
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>
<– End Google Adsense code –>
I would love to create something like that.I am doing a similar service as a project and would like users to upload an image (advertisement) and then have them click a link 'generate ad code' and then they will receive a similar piece of code snippet like the one above in which they can paste into their website.
Any help on this would be great, Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以实现此目的 -
您可以将上传到服务器的可点击广告图像托管在 IFrame 中。基本上,您将向用户提供 IFrame 的 HTML 代码,该代码将根据作为查询字符串传递的广告 ID 加载广告。
您还可以使用由锚标记包围的简单图像标记作为链接。该图像将根据广告标识符从动态页面加载。
示例 1
示例 2
第一个示例将使用包含广告 ID 的 URL 加载 iframe。
ad.aspx
页面将根据查询字符串中传递给它的 ID 动态生成广告。第二个示例将用户重定向到广告跟踪器页面,该页面将跟踪广告已被点击,然后根据广告 ID 重定向用户。
imageserver.aspx
页面将提供广告图像。There are many ways to do this -
You can host the clickable ad image uploaded to the server in an IFrame. Basically you'll be giving the user the HTML code for an IFrame which will load the ad based on an advertisement id passed as a query string.
You can also use a simple image tag surrounded by an anchor tag acting as a link. The image will be loaded from a dynamic page based on the ad identifier.
Example 1
Example 2
The first example will load the iframe with a URL containing the ad id. The
ad.aspx
page will dynamically generate the ad based on the id passed to it in the query string.The second example will redirect the user to an ad tracker page, which will track that the ad has been clicked, and then based on the ad id, the user will be redirected. The
imageserver.aspx
page will serve the ad image.我想我可能会遗漏一些东西......我假设你想用 Javascript 来做到这一点?您将把基本代码作为 javascript 中的字符串(在我的示例中为
strScript
)。然后你只需替换正确的值,并将其放入文本框中?最后一行可能有点偏离,但你能够弄清楚。
I think I might be missing something... I'm assuming you're want to do this with Javascript? You would have your base code as a string in javascript (
strScript
in my example). Then you just replace the proper values, and throw it in a textbox?That last line might be a tad off, but you'll be able to figure it out.