0

I have a page with some iframes. I can't control the content on the actual content of the iframe, but I want to link it to another page. Let's say this way: When I click anywhere inside the iframe, I want to be redirected to eg. google.com. Generally the whole iframe is a button.

I believe this can be done using js.

        <section id="menu">
            <iframe id="button1" src="http://content.captive-portal.com/buttons/w8/mode/free-sms/button.html" target="_top" frameset frameborder=0 scrolling="no"></iframe>
            <iframe id="button1" src="http://content.captive-portal.com/buttons/w8/mode/knights-and-dragons/button.html" target="_top" frameset frameborder=0 scrolling="no"></iframe>
        </section>


function () {
    $("#button1").on('click', function(){
        window.location = "http://www.google.com/";    
    });
    $("#button2").on('click', function(){
         window.location = "http://www.apple.com/";    
    });    
    };

example here:jsfiddle.net/tucado/t5Ca2/1

Piotr Ciszewski
  • 1,691
  • 4
  • 30
  • 53
  • If the iframes have pages from a different domain than the main window, you can't do anything. Refer to the `same origin policy`. – emerson.marini Jun 02 '14 at 15:31
  • If they're all on the same domain, this could be useful: http://stackoverflow.com/questions/16792953/onclick-function-doesnt-fire-on-iframe – emerson.marini Jun 02 '14 at 15:32
  • ok, this is what I've done. It's now working: http://jsfiddle.net/tucado/AxJHH/25 (for future records, maybe someone will have any need for the answer) – Piotr Ciszewski Jun 03 '14 at 00:03

0 Answers0