首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript弹出框不弹出

Javascript弹出框不弹出
EN

Stack Overflow用户
提问于 2011-10-14 14:42:49
回答 4查看 190关注 0票数 0

我试图通过javascript打开一个窗口,但它一直在刷新,什么也没做。一开始我以为它只是Google Chrome,但它在firefox和IE上也是一样的。不知道我的问题出在哪里。JSFiddle说了一些关于"POST“的东西,但我不确定。有什么建议吗?

http://jsfiddle.net/uBwvx

代码语言:javascript
复制
function romantic()
{
    document.body.bgColor = "pink";
    document.body.style.color = "red";
    document.images[1].src = "rom_main.jpg";

    // Searched online to find a script to override some styles. 
    // For loop with adding styles to each anchor didn't work for some reason. Kept being overriden somehow.
    var styleElement = document.createElement("style");
    styleElement.type = "text/css";
    if (styleElement.styleSheet) {
      styleElement.styleSheet.cssText = "a { color: red }";
    } else {
      styleElement.appendChild(document.createTextNode("a { color: red; }"));
    }
    document.getElementsByTagName("head")[0].appendChild(styleElement);
}

function adventure()
{
    document.body.bgColor = "#CDAA7D";
    document.body.style.color = "#5C3317";
    document.images[1].src = "adv_main.jpg";

    var styleElement = document.createElement("style");
    styleElement.type = "text/css";
    if (styleElement.styleSheet) {
      styleElement.styleSheet.cssText = "a { color: #5C4033 }";
    } else {
      styleElement.appendChild(document.createTextNode("a { color: #5C4033; }"));
    }
    document.getElementsByTagName("head")[0].appendChild(styleElement);
}

function relax()
{
    document.body.bgColor = "#B2DFEE";
    document.body.style.color = "#00688B";
    document.images[1].src = "rel_main.jpg";

    var styleElement = document.createElement("style");
    styleElement.type = "text/css";
    if (styleElement.styleSheet) {
      styleElement.styleSheet.cssText = "a { color: #000080 }";
    } else {
      styleElement.appendChild(document.createTextNode("a { color: #000080; }"));
    }
    document.getElementsByTagName("head")[0].appendChild(styleElement);
}

function family()
{
    document.body.bgColor = "#F0E68C";
    document.body.style.color = "#FFA54F";
    document.images[1].src = "fam_main.jpg";

    var styleElement = document.createElement("style");
    styleElement.type = "text/css";
    if (styleElement.styleSheet) {
      styleElement.styleSheet.cssText = "a { color: #6B4226 }";
    } else {
      styleElement.appendChild(document.createTextNode("a { color: #6B4226; }"));
    }
    document.getElementsByTagName("head")[0].appendChild(styleElement);
}

function open()
{
    mywindow = window.open("http://www.javascript-coder.com", "mywindow", "location=1,status=1,scrollbars=1,  width=100,height=100");
    mywindow.moveTo(0, 0);

}
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-10-14 14:59:22

伙计,把你的函数名改为winopen: open是一个关键字,我确信是这样的:

http://jsfiddle.net/uBwvx/11/

票数 1
EN

Stack Overflow用户

发布于 2011-10-14 14:56:51

你的问题是你在“窗口”的范围内定义了open。在JavaScript中定义的所有变量和函数都被分配给window对象。以下内容具有相同的效果:

代码语言:javascript
复制
var myVar = 10;
window.myVar = 10;

因此,请执行以下操作:

代码语言:javascript
复制
function open() { ... }
window.open = function() { ... }

所以你可以看到,你的函数覆盖了window.open,实际上造成了堆栈溢出。任何其他函数名都可以使用,如openWindow()

票数 1
EN

Stack Overflow用户

发布于 2011-10-14 14:47:40

我不确定这是否解决了您的问题,但是您在href中丢失了一个散列。

试一试

<a href="#" onclick="open()">Request A Brochure...</a>

而不是

<a href="" onclick="open()">Request A Brochure...</a>

幸运

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7763962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档