locked
Change all <a> tag's target in iframe in windows store app? RRS feed

  • Question

  • Hi all,

    I now building a windows store app and having a page that load external page in the iframe. The page is having <a> tag and when I click that my iframe is redirect to the url in its href. I want all <a> tag in iframe to open the browser instead of redirect itself, so how can I do that?
    The solution I think of is change all <a> tag's target to "_blank" but it seem like I can't do that inside iframe.

    Thanks in advanced.

    Friday, June 21, 2013 9:15 AM

All replies

  • Like this:

    var frame = document.getElementById("tab").contentDocument;   
    
    //Include in function or event.
    var tags = frame.getElementsByTagName("a");   
    for (var i = 0; i < tags.length; i++) {   
        tags[i].target= '_blank';  
    }
    Hope this helps!

    • Proposed as answer by Chad_Adams Tuesday, June 25, 2013 10:00 PM
    • Edited by Chad_Adams Tuesday, June 25, 2013 10:00 PM Changed code block for javascript highlighting
    Tuesday, June 25, 2013 9:59 PM
  • Hi Chad,

    var iframe = element.querySelector("#news_iframe").contentDocument;

    Give me an Access is denied error.

    Wednesday, June 26, 2013 5:43 AM