开发者

Javascript Popup Box Will Not Pop Up

开发者 https://www.devze.com 2023-04-12 18:48 出处:网络
I\'m trying to open a window via javascript but it keeps just refreshing doing nothing. At first I thought it was just Google Chrome but it did the same in firefox and IE. Not sure what my problem is.

I'm trying to open a window via javascript but it keeps just refreshing doing nothing. At first I thought it was just Google Chrome but it did the same in firefox and IE. Not sure what my problem is. JSFiddle says something about "POST" but I'm not sure. Suggestions?

http://jsfiddle.net/uBwvx:

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; }"));
    }
    documen开发者_Python百科t.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);

}


dude change the name of your function to winopen: open is a keyword IM SURE OF IT:

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


Your problem is that you are defining open in the scope of "window". All variables and functions defined in JavaScript are assigned to the window object. The following have the same effect:

var myVar = 10;
window.myVar = 10;

So do these:

function open() { ... }
window.open = function() { ... }

So you see, your function is overwriting window.open and actually creating an stack overflow. Any other function name should work, like openWindow()


I am not sure if this fixes your problem, but you are missing a hash in the href.

try

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

instead of

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

luck


You use a function called "open()". Since there is no scope defined, this function is put in the "window" scope (which means: you overwrite the standard "window.open()" function.

Renname your function, everything should work ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消