如何动态地设置" SRC"对于浏览器或iframe元素(Firefox扩展) [英] How to dynamically set "src" for browser or iframe element (Firefox extension)

查看:298
本文介绍了如何动态地设置" SRC"对于浏览器或iframe元素(Firefox扩展)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个使用Flex应用程序Firefox扩展。我曾试图把它包在XUL类型(小于IFRAME>和<浏览器>)和我没有preference为我用哪一个......任何作品

I am trying to create a Firefox extension that uses a flex application. I have tried to wrap it in XUL types (<iframe> and <browser>) and I have no preference as to which one I use... whichever works.

问题是,每当我使用相对路径(访问通过镀铬://或mySWF.html)闪光灯无法加载

The problem is that whenever I use a relative path (access through chrome:// or mySWF.html) the flash fails to load.

我要寻找的绝对路径(它贴在下面)的方法,但我不能为我的生活想出一个办法来动态改变任何的iframe或浏览器的src。

I have a method to search for the absolute path (it's posted below) but I cannot for the life of me figure out a way to dynamically change the src of either an iframe or browser.

 <script type="text/javascript">
 function loadSWF() {
  alert("loadSWF!");
  var fullPath = "file:///" + extensionPath.path.replace(/\\/g,"/") +  "/chrome/content/HelloWorld.html";
  top.document.getElementById('AppFrame').setAttribute("src",fullPath);
 }
 </script>

下面是我的2调用Flex应用程序的方法:

Below are my 2 methods of calling the flex app:

 <iframe
  type="content"
  src=??????
  flex="1"
  id="AppFrame"
  name="AppFrame"
  onLoad="loadSWF();"/>

 <browser 
  id="browserid"
  type="content"
  src=??????
  flex="1"/>

我怎么能说我的函数来设置src属性???

How can I call my function to set the src attribute???

推荐答案

1)动态设置的src 工作正常(见下面的测试用例)。

1) Dynamically setting src works fine (see testcase below).

2)获取文件的URL使用nsIIOService.newFileURI()的而不是试图手工转换。

2) To get a URL of a file, use nsIIOService.newFileURI() instead of trying to convert by hand.

3)的onLoad =loadSWF();在你的iframe是可疑的,你应该已经发布了完整的XUL code,显示它如何组合在一起。你应该叫loadSWF不从iframe的加载处理,但是从你的XUL文件的加载处理程序或关闭其他事件。

3) onLoad="loadSWF();" in your iframe is suspicious, you should have posted the complete XUL code that shows how it all fits together. You should call loadSWF not from the iframe's load handler, but from your XUL document's load handler or off another event.

测试用例#1:

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="yourwindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script type="text/javascript">
<![CDATA[
function f() {
 document.getElementById("z").setAttribute("src", "http://google.com/")
}
]]>
</script>
<iframe type="content" id="z"/>
<button onclick="f()"/>
</window>

这篇关于如何动态地设置&QUOT; SRC&QUOT;对于浏览器或iframe元素(Firefox扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆