views:

90

answers:

1

I have a website with multiple pages. All of the pages have an embedded IFRAME in them (always the same iframe src).

My problem is that the iframe contains some statistical tracking code, (like statcounter), and statcounter only shows the name of the iframe as the page being visited.

Is it possible somehow to include a few lines of javascript to change the filename to make it equal to the main webpage name, so the stats shown on statcounter, show the real HTML name, and not the iframe name??

Any kind soul care to show me what lines of code I could insert to do that?

thanks for any help, regards, mango.

A: 

From inside the iFrame your javascript would reference parent.document.[whatever you're accessing]. Changing those lines in your tracking code should get you what you're looking for.

To do it conditionally in case your iFrame source isn't always embedded you could write it as:

if (parent){var doc = parent.document;}
else{var doc = document;}
doc.[whatever attribute]
Gabriel Hurley
If you want to post the actual javascript for your stat counting code I'm sure I could point to what needs changing. But somewhere in there it should reference things like document.title or window.title or window.location... things of that sort. Those are the lines you need to prepend the "parent" to.
Gabriel Hurley
thanks. this is basically my entire iframe content:<body><!-- Start of StatCounter Code --><script type="text/javascript"src="http://www.statcounter.com/counter/counter.js"></script><!-- End of StatCounter Code --></BODY>As you can see, I cannot access the statcounter javascript to change it. I figure there must be some way to make statcounter realise the real document name and not the iframe..?
Basically, to clarify, if my main webpage is A[1-150].html, and it embeds iframe B.html, I want the statcounter code within B.html to log the name as A[1-150].htmlwhere A[1-150].html can be A1, A2, A3.. A150.html - Sorry for any confusion, not exactly sure if I explained correctly.
Looking at the *unpleasantly minified source code* for statcounter, you'd have an unpleasant time trying to make that do what you want. There is no magic way to tell it to look at the parent window, and doing something like overriding the global document variable is a *very bad idea* if it would even let you. You would basically have to tweak their code and serve your own version of it. It doesn't look like they intended it to work quite right inside an iFrame. You could try emailing their support though and see what they say.
Gabriel Hurley
Gabriel, thanks for your help. I guess seeings as what I wanted isn't possible, I wonder if you know of another way I can embed HTML code into my webpages? Is it not possible for a group of HTML pages to somehow fetch html code from a central html file, that can easily be updated and changed without touching the main files? would the <embed> tag let me do that?