javascript弹出消息只出现一次
我正在制作一个有两种模式的chrome扩展,每当点击图标时,就会出现一条弹出消息,向用户解释他处于哪种模式 问题是消息并不总是显示(弹出窗口本身被打开) 我试着用谷歌搜索,但似乎没有多少人遇到这个问题 有人能帮忙吗 这是我的密码:javascript弹出消息只出现一次,javascript,html,google-chrome-extension,popup,Javascript,Html,Google Chrome Extension,Popup,我正在制作一个有两种模式的chrome扩展,每当点击图标时,就会出现一条弹出消息,向用户解释他处于哪种模式 问题是消息并不总是显示(弹出窗口本身被打开) 我试着用谷歌搜索,但似乎没有多少人遇到这个问题 有人能帮忙吗 这是我的密码: function openWin1() { myWindow=window.open('','','width=500,height=500,toolbar=0, location=0, status=0, menubar=0, scrollbars=0, r
function openWin1()
{
myWindow=window.open('','','width=500,height=500,toolbar=0, location=0, status=0, menubar=0, scrollbars=0, resizable=0');
myWindow.moveTo(500,100);
myWindow.document.write("<p>mode1</p>");
myWindow.focus();
}
function openWin2()
{
myWindow=window.open('','','width=500,height=500,toolbar=0, location=0, status=0, menubar=0, scrollbars=0, resizable=0');
myWindow.moveTo(500,100);
myWindow.document.write("<p>mode2</p>");
myWindow.focus();
}
chrome.browserAction.onClicked.addListener(onClickExtensionIcon);
function onClickExtensionIcon(tab)
{
if(hasAPrise)
{
hasAPrise = false;
chrome.browserAction.setIcon({path: '/icon.png'});
openWin1(); //open the first popup
}
else
{
openWin2(); //open the second popup
}
}
函数openWin1()
{
myWindow=window.open(“”,,“宽度=500,高度=500,工具栏=0,位置=0,状态=0,菜单栏=0,滚动条=0,可调整大小=0');
myWindow.moveTo(500100);
myWindow.document.write(“mode1”);
myWindow.focus();
}
函数openWin2()
{
myWindow=window.open(“”,,“宽度=500,高度=500,工具栏=0,位置=0,状态=0,菜单栏=0,滚动条=0,可调整大小=0');
myWindow.moveTo(500100);
myWindow.document.write(“mode2”);
myWindow.focus();
}
chrome.browserAction.onClicked.addListener(onclickExtensionOn);
函数onClick扩展(选项卡)
{
if(hasAPrise)
{
hasAPrise=假;
chrome.browserAction.setIcon({path:'/icon.png'});
openWin1();//打开第一个弹出窗口
}
其他的
{
openWin2();//打开第二个弹出窗口
}
}
提前谢谢
编辑:我注意到,如果我将弹出窗口最大化和最小化几次,消息就会出现。此外,当我检查弹出源时,信息是否正确。这很有趣。有没有办法解决这个问题 写入文档后必须关闭该文档:
myWindow.document.write("<p>mode2</p>");
myWindow.document.close();
myWindow.document.write(mode2);
myWindow.document.close();
更新:为目标命名可能也很有用,这样您就不会每次单击链接时都生成一个新窗口,或者用html包装您的内容
function openWin1(){
myWindow=window.open('','popup1','width=500,height=500,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
myWindow.moveTo(500,100);
myWindow.document.write("<html><head><title>Popup1</title></head><body>I am popup 1</body></html>");
myWindow.document.close();
myWindow.focus();
myWindow.resizeTo(499,499); //UPDATE: force resize because OP is getting improved results after window resize
}
函数openWin1(){
myWindow=window.open(“”,'popup1','width=500,height=500,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
myWindow.moveTo(500100);
myWindow.document.write(“Popup1I am popup1”);
myWindow.document.close();
myWindow.focus();
myWindow.resizeTo(499499);//更新:强制调整大小,因为OP在调整窗口大小后获得了更好的结果
}
我无法将其作为一个实际的Chrome扩展进行测试,但我已经做出了什么消息没有显示出来?我在您的代码中没有看到一个。
myWindow.document.write(mode1);和myWindow.document.write(“mode2”)代码>打开第一个弹出窗口时,应显示mode1,第二个弹出窗口应显示MODE2TANKS或答案,但不起作用。任何其他建议:(尝试过,但没有效果。似乎出于某种原因,文本只有在我重新调整窗口大小或查看源代码后才会加载。非常奇怪。也许你可以强制调整大小:`myWindow.resizeTo(499499);'不,仍然不起作用。Javascript不太喜欢我