0

I have a problem with hover effect on elements that are inside <iframe>.

Code inside iframe, it's in domainA.com

<!doctype html>
<html>
  <head>
      <meta charset="utf-8">
      <style>
          img:hover {
            opacity: 0.5;
          }
      </style>
 </head>
 <body>
     <img src="/image1.jpg">
     <img src="/image2.jpg">
     <img src="/image3.jpg">
 </body>
</html>

And second website on domainB.com

<iframe src="domainA.com/iframe.html">

When i embed iframe in domainB hover effect doesn't work. Is there any way to solve it somehow? I don't have access to code of domainB.com (other developer will put iframe there)

Krystian
  • 996
  • 9
  • 24

1 Answers1

1

If you want this effect work,you should link this css to inside your iframe.

a.html:

<html>
<body>
<iframe src="b.html" ></iframe>
</body>
</html>

b.html:

<html>
<head>
<style>
img:hover{
   opacity: 0.5;
}
</style>
</head>
<body>

<img src="xx.jpg" />
</body>
</html>

Otherwise use javascript to do this...like:

$(document.getElementById('Iframe_id').contentWindow.document.body).find("image").mouseover(function(){
   alert("do what you want here");
});

Be sure this code is inside $(documet).ready();

aksu
  • 5,221
  • 5
  • 24
  • 39
Raymond Cheng
  • 2,425
  • 21
  • 34