MJ
asked on
Removing iframe elements
I have the following code for injecting DoubleClick tags on a page:
// DOM Injection routines
var iframeTag = document.createElement("iframe");
iframeTag.setAttribute("width", "1");
iframeTag.setAttribute("height", "1");
iframeTag.style.display = "none";
iframeTag.style.border = "none";
iframeTag.src = dcUrlBuilder("//fls.doubleclick.net/activityi", src, type, cat, "1");
var ref = document.getElementsByTagName("script")[0];
ref.parentNode.insertBefore(iframeTag, ref);
It dynamically creates DoubleClick Tags and injects them into the page using an iFrame. I'm now working with a MVC framework so what I now need to do is remove every tag that was created on the previous view. I have no idea how to approach this? Is there a way to do this?
ASKER
Sorry, this is hard to explain. Yes, a new view is loaded but there is no http call therefore the iFrame still exists.... wouldn't it? That's what I'm assuming. The MVC framework an ASP.net framework. I'm loading the DoubleClick tags via Adobe DTM.
Ok I'm out if my depth with .net stuff. I use php based mvc. I have heard about partial post backs but not sure if that's related. sorry. I'll get another expert involved
I, too, don't quite get what you are trying to achieve. Are you trying to figure out how to remove an element from the DOM from a different HTML page?
ASKER
Hopefully this helps explain a little more? I have double click tags that are dynamically loaded based on the current view. So when View1 renders I want to load doubleclick tags A & B. Then when a new View2 renders I want to load doubleclick tags C, D, E & F. The issue is, Tags A & B will also still be there so View2 will have tags A-F instead of C,D, E &F. I need a way to eliminate/unload Tags A & B.
Are tags A & B in different iframes from tags C, D, E & F? You would need to be able grab a reference to the tag, and then remove it from its parent.
ASKER
The tags are in the same iFrame.
ASKER
I was wondering if I name the iFrame, can I close it before recreating?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here's what worked for me. I just gave the iFrame and ID and then closed it using the ID.
var iframeTag = document.createElement("if rame");
iframeTag.setAttribute("wi dth", "500");
iframeTag.setAttribute("he ight", "500");
iframeTag.setAttribute("id ", "dc_target");
iframeTag.style.display = "none";
iframeTag.style.border = "none";
iframeTag.src = dcUrlBuilder("//fls.double click.net/ activityi" , src, type, cat, "1");
var ref = document.getElementsByTagN ame("scrip t")[0];
ref.parentNode.insertBefor e(iframeTa g, ref);
and then do this:
var frame = document.getElementById("d c_target") ;
frame.parentNode.removeChi ld(frame);
var iframeTag = document.createElement("if
iframeTag.setAttribute("wi
iframeTag.setAttribute("he
iframeTag.setAttribute("id
iframeTag.style.display = "none";
iframeTag.style.border = "none";
iframeTag.src = dcUrlBuilder("//fls.double
var ref = document.getElementsByTagN
ref.parentNode.insertBefor
and then do this:
var frame = document.getElementById("d
frame.parentNode.removeChi
When you load a view you're loading a completely new page so I'm not understanding what you mean by removing the tags from the previous view.
My understanding is when you load the new view, the previous view is replaced.
What mvc framework ate you using?