Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

jQuery Mobile + iframe causes the parent page to jump to the iframe when a link is clicked #560

Closed
@JamesNK

Description

@JamesNK

Clicking a link in jQuery Mobile when the page is embedded in an iframe causes the parent page to jump to the top of the iframe.

Activity

toddparker

toddparker commented on Dec 10, 2010

@toddparker
Contributor

We'll keep this in the tracker but this is sort of an issue with demoing mobile on a desktop browser, right?

JamesNK

JamesNK commented on Dec 10, 2010

@JamesNK
Author

Yes. Overall it works quite well and the jQuery Mobile page inside the frame looks perfect, the only issue is the jump to the iframe when navigating.

ghost

ghost commented on Jan 25, 2011

@ghost

+1

scottbw

scottbw commented on Mar 12, 2011

@scottbw

I've seen this in Safari - clicking back on a page inside an iFrame moves focus on first click, on second click it triggers the back function on the top frame instead :-/

However, just editing the JQM history function from window.history.back() to use self.history.back() instead seems to fix it.

scottbw

scottbw commented on Mar 12, 2011

@scottbw

D'oh my mistake, using "history.back" instead of "window.history.back" makes it work on Safari.

scottbw

scottbw commented on Mar 12, 2011

@scottbw

Actually, scratch that. Using JQuery Mobile for multiple apps in iFrames shows up some very strange behaviour when it comes to the "back" button.

It works fine in Chrome (apart from the jump)

In Firefox, if you have two iFrames with jQM content, the back button affects a change in whichever one you changed last and NOT the one where you actually clicked.

In Safari, back behaves in a very odd and erratic way. Sometimes it works, sometimes it doesn't (hence my false positives above).

Ouch.

I've tried replacing history.back with:

var url = $.mobile.urlHistory.getPrev().url;
if (url === null || url == "") url = $.mobile.firstPage.attr("data-url");
url = "#" + url;
$.mobile.changePage(url, "slide", true); 

Which almost works, except if you have more than two levels, you just ping-pong between levels two and three and can never get back up to the first page.

toddparker

toddparker commented on Mar 12, 2011

@toddparker
Contributor

Thanksfor looking into this. If you find a workable solution, let us know!

scottbw

scottbw commented on Mar 13, 2011

@scottbw

No worries, I'd love to solve this one!

I've got a solution for now using:

var url = $.mobile.urlHistory.getPrev().url;
if (url === null || url == "") url = $.mobile.firstPage.attr("data-url");
url = "#" + url;
$.mobile.changePage(url, "slide", true, true, true);

This seems to work fine in Safari, Chrome and Firefox on Mac.

SorraTheOrc

SorraTheOrc commented on Mar 14, 2011

@SorraTheOrc

In terms of use case I'd like to point out that this is not just an issue when demoing in a browser.

Projects like Apache Rave (Incubating) are building web based portals that use W3C Widgets and OpenSocial gadgets as the "portlets". It is reasonable to expect some of these to be built with libraries such as JQueryMobile.

toddparker

toddparker commented on Mar 15, 2011

@toddparker
Contributor

@scottbw - If you work this out, please post a pull request and we'll takea look at adding it.

scottbw

scottbw commented on Mar 16, 2011

@scottbw

@toddparker will do.

dacosta-rafael

dacosta-rafael commented on Mar 30, 2011

@dacosta-rafael

i have an or <iframe> page. how can i get links on the iframed page to target the parent when linking with jquery mobile data-rel="dialog" data-transition="pop"

toddparker

toddparker commented on Mar 30, 2011

@toddparker
Contributor

So you have JQM running in an iframe and want a link inside the JQM frame to target the parent window? Does the target attribute work?

In any case, you're not going to be able to cause a transition in the parent window. There a lot fo complexity going to make transitions work in JQM.

dacosta-rafael

dacosta-rafael commented on Mar 30, 2011

@dacosta-rafael

target attribute fails and is not as intuitive to the jqm

i need to display a page with a moving carousel, on slide -- not changing page but showing item in carousel on slide only (w/o page reload). in the carousel the items are then linked to a jqm dialog. how can i do this w/o iframe or embed

toddparker

toddparker commented on Mar 30, 2011

@toddparker
Contributor

This just doesn't seem like an issue per se. Please post this to the support forums instead.

dacosta-rafael

dacosta-rafael commented on Mar 30, 2011

@dacosta-rafael

where is the support forum? will post

scottjehl

scottjehl commented on Apr 1, 2011

@scottjehl

At least at this time, making our history model work within an iframe isn't a project priority. We've added this and its related pull request to the feature requests wiki for later consideration. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @scottjehl@SorraTheOrc@JamesNK@toddparker@scottbw

        Issue actions

          jQuery Mobile + iframe causes the parent page to jump to the iframe when a link is clicked · Issue #560 · jquery-archive/jquery-mobile