Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:40:39+00:00 2026-05-29T22:40:39+00:00

I have an iframe (same domain), and want to be able to track the

  • 0

I have an iframe (same domain), and want to be able to track the button usages inside the iframe from the parent page.

The reason I don’t want to embed the tracking directly into the iframe is that I share the iFrame across different pages and want to be able to track it’s unique usage by the parents page tracking events in jQuery.

Sample HTML inside the iFrame:

   <a class="btn1" href="1.html">button 1</a>
   <a class="btn2" href="2.html">button 2</a>
   <a class="btn3" href="3.html">button 3</a>
   <a class="btn4" href="4.html">button 4</a>

jQuery inside parent page :

$(document).ready(function() {  
  $('.btn1').click(function () {
  _gaq.push(['_trackEvent', 'iframe page', 'iframe buttons', button 1]);
  });
  $('.btn2').click(function () {
  _gaq.push(['_trackEvent', 'iframe page', 'iframe buttons', button 2]);
  });
  $('.btn3').click(function () {
  _gaq.push(['_trackEvent', 'iframe page', 'iframe buttons', button 3]);
  });
  $('.btn4').click(function () {
  _gaq.push(['_trackEvent', 'iframe page', 'iframe buttons', button 4]);
  });
});

This isn’t working though. If I view the parent page source, there’s only the iFrame reference, none of the HTML – so I’m assuming that the parent page doesn’t see any of the iFrames div classes to attached the click event?

I’m very new to jQuery… so apologies if I’m missing some gapingly obvious error!

EDIT 1:

I’ve now tried amending the script on the parent page to:

$(document).ready(function() {  
  $('.iframe').contents().find('.btn1').click(function () {
  alert("Button 1 Pressed!");
  });
  $('.iframe').contents().find('.btn2').click(function () {
  alert("Button 2 Pressed!");
  });
  $('.iframe').contents().find('.btn3').click(function () {
  alert("Button 3 Pressed!");
  });
  $('.iframe').contents().find('.btn4').click(function () {
  alert("Button 4 Pressed!");
  });
});

and assigned the iframe the class=”iframe”.

When I click on the button inside the iframe from the parent page – no alert is triggered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:40:40+00:00Added an answer on May 29, 2026 at 10:40 pm

    For anyone that stumbles across this thread and is looking for a similar answer – with the help of other stackoverflow posts (and some corrected code from: deantoni) and some long-winded Google threads, this was the solution that I came to that works.

    The assumptions are:

    • The iFrame is editable.
    • Is under the same domain.
    • You have the Google Analytics tracking code in the parent frame, with event tracking support.

    The iFrame HTML used:

    <a class="button1" href="1.html">button 1</a>
    

    The iFrame jQuery used:

    $(document).ready(function() {  
      $('.button1').click(function() {
        window.parent.triggerButton1();
      });
    });
    

    The Parent Frame jQuery used:

        window.triggerButton1 = function (){
            _gaq.push(['_trackEvent', 'iframe page', 'iframe buttons', 'button 1']);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iframe in the same domain as the web page. I have
I have an iframe embedded inside a fan page of FB, and I want
Lets say I have a page on the same domain that I put inside
i know i can have iframe in a html page, say parent.htm, and i
I have an iframe pointing to arbitrary foreign domain http://A . I want to
I have an iframe in my page and I want to display the content
Basically I have an iframe loaded that is accessed from the parent whenever it
I have an iframe that loads a remote page (not hosted on the same
I have a iframe and want to either get some of the HTML from
First the two page in under the same domain In the parent page.htm I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.