打开一个新的选项卡/窗口,并写一些东西呢? [英] Open a new tab/window and write something to it?

查看:121
本文介绍了打开一个新的选项卡/窗口,并写一些东西呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用执行JS 来编写和测试Javascript代码在Firefox内。我想打开一个新的标签页/窗口,并写了一些东西,我试过

pre $ var wm = Components.classes [@ mozilla.org/appshell/window-mediator;1\"].getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow(navigator:browser);
printWindow = win.open(about:blank);
printWindow = wm.getMostRecentWindow(navigator:browser);
printWindow.gBrowser.selectedBrowser.contentDocument.write('hello');



  myWindow = window.open('','','width = 200,height = 100')
myWindow.document.write(< p>这是'myWindow'< / p> ;)
myWindow.focus()

但是我总是得到这个错误


<例外...操作不安全。代码:18nsresult:
0x80530012(SecurityError)

有没有办法解决这个异常?

解决方案

不要写入窗口,只需打开它所需的内容:
$ b

  var data =< p>这是'myWindow'< / p> 
myWindow = window.open(data:text / html,+ encodeURIComponent(data),
_blank,width = 200,height = 100);
myWindow.focus();

供参考: data URIs


I'm using Execute JS to write and test Javascript code within Firefox. I want to open a new tab/window and write something to it and I tried

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
printWindow = win.open("about:blank");
printWindow = wm.getMostRecentWindow("navigator:browser");
printWindow.gBrowser.selectedBrowser.contentDocument.write('hello');

And

myWindow=window.open('','','width=200,height=100')
myWindow.document.write("<p>This is 'myWindow'</p>")
myWindow.focus()

However I always get this error

[Exception... "The operation is insecure." code: "18" nsresult: "0x80530012 (SecurityError)"

Is there any way to get through this exception?

解决方案

Don't "write" to the window, just open it with the contents you need:

var data = "<p>This is 'myWindow'</p>";
myWindow = window.open("data:text/html," + encodeURIComponent(data),
                       "_blank", "width=200,height=100");
myWindow.focus();

For reference: data URIs

这篇关于打开一个新的选项卡/窗口,并写一些东西呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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