1

Is there a way to remove all anchor title attributes in all links within an iframe so that when you hover over them you don't get the title?

I know I can do something like the following but for some reason it isn't working.

$("iframe").load(function() {
    $("iframe").contents().find("a").each(function(index) {
      $(this).attr('title','');
    });
});
halfer
  • 19,471
  • 17
  • 87
  • 173
bryan
  • 8,279
  • 15
  • 74
  • 148
  • Is the iframe loaded from the same domain, protocol etc. – adeneo Jun 01 '17 at 20:37
  • No, completely different domain. I'm just trying to kill the anchor hovers because they are quite annoying in this instagram plugin @adeneo – bryan Jun 01 '17 at 20:39
  • See this question/answer: https://stackoverflow.com/questions/6170925/get-dom-content-of-cross-domain-iframe – CodeLikeBeaker Jun 01 '17 at 20:45
  • 1
    ^ That's the reason for asking, the same origin policy prohibits you from accessing content not loaded from the same domain, so basically you can't do this. – adeneo Jun 01 '17 at 20:57

4 Answers4

1

This will work for you on the same domain:

 $('iframe').load(function(){
        $(this).contents().find('a').removeAttr('title');
 })

If you are not on the same domain, it will not work. See the following SO Question/Answer:

Get DOM content of cross-domain iframe

CodeLikeBeaker
  • 19,633
  • 13
  • 75
  • 105
1

If iframe uses same protocol and domain, you can change iframe's content.

Different protocol or domain will generate an Security Exception.

0

Given the contents of iFrame is from same domain you can use the following for every anchor tag

$('a').removeAttr('title');
Nawed Khan
  • 4,336
  • 1
  • 9
  • 21
0

Try This:

Javascript: Demo

var iframe = document.getElementById('iframeId');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;

var links = innerDoc.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
  links[i].removeAttribute("title");
}

Jquery: Demo

setTimeout( function () {
      $("#iframeId").contents().find("a").removeAttr("title");
}, 1000 );
Ali Hesari
  • 1,697
  • 4
  • 21
  • 47