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);

Open in new window

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?
894359Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Bear with me while I work out what you're trying to do...
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?
894359Author Commented:
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.
RobOwner (Aidellio)Commented:
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Bob LearnedCommented:
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?
894359Author Commented:
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.
Bob LearnedCommented:
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.
894359Author Commented:
The tags are in the same iFrame.
894359Author Commented:
I was wondering if I name the iFrame, can I close it before recreating?
Bob LearnedCommented:
When you say "close" do you mean "hide" or "remove" it?  You should be able to remove it, and then re-add it with different tags.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
894359Author Commented:
Here's what worked for me. I just gave the iFrame and ID and then closed it using the ID.

var iframeTag = document.createElement("iframe");
            iframeTag.setAttribute("width", "500");
            iframeTag.setAttribute("height", "500");
         iframeTag.setAttribute("id", "dc_target");
            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);

and then do this:

 var frame = document.getElementById("dc_target");
            frame.parentNode.removeChild(frame);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.