views:

34

answers:

2

Hi,

I've got a PHP page serving content into an Iframe on another website, and it needs to re-load content inside the Iframe according to user interaction on the host website. The page content that's inside the Iframe contains multiple URLs.

In order for the Iframe interaction to work, I was thinking of using a request parameter in the URLs that identifies that it's a call for the Iframe --- in order to reload the content with custom formatting/styles/behavior for the host website, instead of treating it as a normal request.

What might be a simple solution for rendering lots of URLs on the page with a custom request parameter, without having to add this manually to the end of every link in the relevant HTML templates?

I've found a few JavaScript-based ideas but they seem a little excessive. Any pointers would be appreciated.

Thanks.

+1  A: 

Though I think it's neater to do this in PHP, in JavaScript you can use something like

function addQueryPart() {
    var allAnchors = document.getElementsByTagName('a');
    var i = allAnchors.length, href;

    while (i--) {
        href = allAnchors[i].href;
        if (href.indexOf('?') > -1)
            href += '&';
        else
            href += '?';

        allAnchors[i].href = href + "inframe=true";
    }
}

Do you need something that works with hashes, too (like foo#withinPage)?

Marcel Korpel
Thanks for this - the php solution above was more suitable, but I've noted this for another time.
Tom
+2  A: 

Check output_add_rewrite_var() PHP function. For example if you call output_add_rewrite_var('my_var', 5) it will add my_var=5 to all local URLs and <hidden name="my_var" value="5" /> to all forms.

Ogre_BGR
Thanks for teaching me about this function... exactly what I need.
Tom