Joel
Joel

Reputation: 62

Open Google Docs iframe link in new window/tab not working in Internet Explorer

I am embedding an iframe in my html page that links to a Google Doc. However, when using Internet Explorer, links open up within the iframe. I would like the link to open in a new window or new tab.

I have searched for an answer to this and have found the following code, but it doesn't work in Internet Explorer or Edge, apparently due to IE not recognising srcdoc

Does anyone know a cross browser solution?

<script src="js/jquery-1.8.3.min.js"></script>

<iframe srcdoc="" frameborder="0" scrolling="no"  style="height:1000px; width:100%"></iframe>

<script>
    $(function() {
        $.get("https://docs.google.com/document/d/1fwt5APDmopqJ6R3aAzg_WCJBhbju1l03DtiSWNbYntg/pub?embedded=true", function(html) {
        var contents = $("iframe").contents();

        contents.find("html").html(html);

        setTimeout(function() {
            contents.find('a[href^="http://"]').attr("target", "_blank");
            contents.find('a[href^="https://"]').attr("target", "_blank");
        }, 1000); 
    });
});

Upvotes: 1

Views: 1058

Answers (1)

Joel
Joel

Reputation: 62

Wow! I think I found a solution

In the code above, just change srcdoc="" to src="" and it works in IE

Could anyone confirm this solution is safe? I don't want to break the internet!

Upvotes: 1

Related Questions