response not displaying correctly in iframe

435 views
Skip to first unread message

simon

unread,
May 6, 2012, 11:33:58 AM5/6/12
to web...@googlegroups.com
Please can someone explain this.....

When I enter test using the code below then I can see a page with "TEST" and  "CONTENTS" which is what I wanted.
However when I open test/4 it shows three nested iframes  each with "TEST"

def test():
    response.view="default/test.html"
    return dict()
def webpage():
    return XML("CONTENTS")

test.html

TEST
<iframe src='webpage.html' scrolling="no" width="100%"></iframe>

Massimo Di Pierro

unread,
May 6, 2012, 1:23:20 PM5/6/12
to web...@googlegroups.com
That;s how html understand paths. Do it the safe web2py way:

<iframe src='{{=URL('webpage.html')}}' scrolling="no" width="100%"></iframe>

simon

unread,
May 6, 2012, 1:39:05 PM5/6/12
to web...@googlegroups.com
Thanks. That seems to work. Though I am still curious as to why test.html works and test.html/4 does not.

pbreit

unread,
May 6, 2012, 1:54:33 PM5/6/12
to web...@googlegroups.com
This is *really* weird code.

Can you show us resulting the HTML source?

As Massimo notes, best to use URL() function for URLs. You generally don't need this: response.view="default/test.html". Shouldn't matter but you could  just do: return 'CONTENTS'

Going to http://myserver.com/myapp/test/4 should be the same as going to http://myserver.com/myapp/test. The '4' is simply disregarded since your controller doesn't look for it.

Anthony

unread,
May 6, 2012, 2:33:04 PM5/6/12
to web...@googlegroups.com
I think the same problem as mentioned here: https://groups.google.com/d/msg/web2py/eS0bKdwuQuY/-v0lBhtIpPgJ. In your iframe, you have src='webpage.html' -- because the URL does not start with a "/", the browser interprets it as being relative to the current URL. So, when the parent page is http://mydomain.com/myapp/default/test, the iframe source becomes http://mydomain.com/myapp/default/webpage.html, which is what you want. But when the parent page is http://mydomain.com/myapp/default/test/4, the iframe source is http://mydomain.com/myapp/default/test/webpage.html, which routes to the test() function with "webpage.html" in request.args[0] -- so you're just nesting iframes of the same page.

Anthony

simon

unread,
May 6, 2012, 3:31:29 PM5/6/12
to web...@googlegroups.com
Well you only have a small extract of what I am doing. Even so it is a little weird so I will explain (any suggestions of alternative ways welcome!):

I want to include within my view some of my own buttons and menus on the left of the screen; plus show an external web page from the internet.

Having an iframe keeps the two parts isolated and prevents conflicts between my CSS and the CSS of the web page.

The iframe source calls a web2py controller which fetches the page from the web. This allows me to make some changes to the web page within web2py before it is loaded in the iframe. It also gives the iframe has the same domain as the parent view which is needed to give the parent javascript access the iframe document.

And I set the response.view because I have several controllers each with a single view and would rather put all the views in one directory (default); whereas normally a controller looks in the view/controller folder.
Reply all
Reply to author
Forward
0 new messages