0

I have the following javascript code which should be able to create a dialog box triggered by an onclick event in the html file. But strangely I alway get the error Uncaught TypeError: Cannot read property 'style' of null. By the way the TypeError concerns the reopenprogram(element) function!!! I have already checked whether the element is really null but putting it in alert showed me the usual element name. I know the code looks a little bit rough but I am free for any suggestions. Here is the jsfiddle code. I am pretty new to javascript so I would be really glad if you could fully adjust the code yourself.

Please help me!

function executeprogram(element) {

var program = document.createElement("div");
var toolbar = document.createElement("div");
var title = document.createElement("div");
var minimize = document.createElement("div");
var close = document.createElement("div");
var iframe = document.createElement("iframe");
var container = document.getElementById("container");

// Create program Div //
program.id = element;
program.className = "dialog";
program.width = iframe.width;
add(element);
program.setAttribute("onmousedown", "dragstart(this)");
container.appendChild(program);

// Toolbar //

toolbar.id = "toolbar";
toolbar.width = iframe.width;
program.appendChild(toolbar);

// Title //

title.id = "title";
title.innerHTML = element;
toolbar.appendChild(title);

// Minimize //

minimize.id = "minimize";
minimize.innerHTML = "-";
minimize.onclick = minimizeprogram(element);
toolbar.appendChild(minimize);

// Close //

close.id = "close";
close.innerHTML = "x";
close.onclick = closeprogram(element);
toolbar.appendChild(close);

// Create Iframe //
iframe.frameBorder = 1;
iframe.width = "500px";
iframe.height = "250px";
iframe.id = "iframe";
iframe.src = "#";
program.appendChild(iframe);
}

// Minimize program //

function minimizeprogram(element) {
    document.getElementById(element).style.display = "hidden"; 
}
function reopenprogram(element) {
    document.getElementById(element).style.visibility = "visible"; 
}

// Close program //

function closeprogram(element) {
    var container = document.getElementById("container");
    var app = document.getElementById(element);

    container.removeChild(app);

    remove(element);
}

// Tabs //

function add(element) {
    var tabs = document.createElement("li");
    tabs.id = ""+element+"tab";
    alert(element);
    tabs.onclick = reopenprogram(element);

    var add = document.getElementById("tabs");  
    add.appendChild(tabs);
}
function remove(element) {
    var add = document.getElementById("tabs");
    var app = document.getElementById(element+"tab");
    add.removeChild(app);
}
4

1 回答 1

1

element在您的小提琴中,您永远不会将具有参数值id 的元素添加到文档中。这就是原因。

于 2012-04-28T09:46:04.363 回答