SORU
12 Ocak 2012, PERŞEMBE


JavaScript DOM element çıkarın

Eğer eleman var, ve eğer bunu silmek varsa, ve eğer yok ise hiç bir DOM oluşturma test etmek için çalışıyorum.

var duskdawnkey = localStorage["duskdawnkey"];
var iframe = document.createElement("iframe");
var whereto = document.getElementById("debug");
var frameid = document.getElementById("injected_frame");
iframe.setAttribute("id", "injected_frame");
iframe.setAttribute("src", 'http://google.com');
iframe.setAttribute("width", "100%");
iframe.setAttribute("height", "400");

if (frameid) // check and see if iframe is already on page
{ //yes? Remove iframe
    iframe.removeChild(frameid.childNodes[0]);
} else // no? Inject iframe
{
    whereto.appendChild(iframe);
    // add the newly created element and it's content into the DOM
    my_div = document.getElementById("debug");
    document.body.insertBefore(iframe, my_div);
}

Eğer işleri varsa kontrol unsuru oluşturmaya çalışıyor, ama eleman silme yok. Bu kod temelde tüm bir düğmeye tıklayarak bir web sayfası içine bir iframe enjekte edilir. Olmasını istediğim şey ise iframe orada zaten silmek için ise. Ama nedense başarısız oldum.

CEVAP
12 Ocak 2012, PERŞEMBE


removeChild üst çağrılması, yani:

parent.removeChild(child);

Sizin örnekte olduğu gibi bir şey yapıyor olmalı:

if (frameid) {
    frameid.parentNode.removeChild(frameid);
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Digital Bounds

    Digital Boun

    19 Temmuz 2013
  • footiecyclo

    footiecyclo

    26 EYLÜL 2009
  • Howcast

    Howcast

    4 EKİM 2007