1

I'm developing my first app using jQuery Mobile and I got a question (didn't find anything in the web). I'm using a navbar with 3 pages.

The first page shows some Wikipedia stuff inside an iframe (keep it in mind)! When I click on the second page (Approfondimenti), it shows a vertical menu with some elements that I can click.

What my jQuery function does (by clicking on one of the menu element in the second page) is to change the iframe 'src' to a new URL... but I don't know how to go back to the first page with my function so my app could show the URL change (don't want manual click on the first page to load iframe content).

Can you help me?

Here is my function:

$(document).on('click', '.a', function(e){ // here i already am in the second page
       var appr=$(this).attr('id'); //here i get the URL from second page, i stored them in the elements id
   $('#iframe').attr('src',appr); //here i set new URL 
       //HERE WHAT TO DO????????
    });

enter image description here

7
  • $(document).on('click', '.a', function(e){ e.preventDefault(); rest of your code }); if I get what you need. Commented Jul 8, 2013 at 16:49
  • no, i don't want to prevent action about the elements in the second page, cause they are just <li>. when i click them, my function is triggered so it change the URL iframe (in page "Foro"). Then i want to go back (or to switch if you like it) to the "Foro" page without clicking it, i want to automate this action directly in my function using some methods. Commented Jul 8, 2013 at 17:41
  • Can you put this in jsfiddle.net because I still can't get what you mean. Commented Jul 8, 2013 at 18:57
  • Here it is! jsfiddle.net/manhunt/q2LJX/5 Just click on "Approfondimenti" and select one item, my function is triggered as it changes iframe URL, but you can see the result only if you click on "Foro" page, i want to automate this in my function. Commented Jul 8, 2013 at 19:05
  • $('.a').on('click', function since .a links are not dynamically added. Commented Jul 8, 2013 at 19:44

1 Answer 1

2

Add this to change page in jQuery mobile:

 $.mobile.changePage("#page1");

Link: http://jsfiddle.net/androdify/q2LJX/9/

Sign up to request clarification or add additional context in comments.

2 Comments

Oh, it works on jsfiddle but not on my browser (desktop). Is it normal?
@alfa it should work on desktop too, probably some other error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.