0

In my code I have a jquery script which has a next & previous page function. The jquery script loads a php script to parse a selected page. The parsed page has a div removed with the name postsArea and is placed into a div with an id of wrap. As of the moment the jQuery script is set up to put the div postsArea into the div wrap. What I want to do is put the div postsArea into a iframe with the id news.

JQuery :

$('document').ready(function () {
    var $wrap = $('#wrap'),
    page = 1;
    $('#next').on('click', function () {
        getPage(++page);
    });
    $('#prev').on('click', function () {
        getPage(--page);
    });
    var getPage = function (page) {
        $wrap.load('proxy.php?page=' + page + ' #postsArea');
    };
    getPage(page);
});


PHP :

<?php
    include( 'site/simple_html_dom.php'); 
    $html=file_get_html( 'http://roosterteeth.com/home.php?page=' . $_GET["page"]);
    echo $html;
?>


HTML :

<body>
<div id="wrap">
</div>
<button type="button" id="next">Next</button>
<button type="button" id="prev">Previous</button>
</body>


I really appreciate any help and thank you for your time.

1
  • is the iframe on the same domain as your script? Commented Dec 23, 2013 at 13:43

1 Answer 1

1

An iframe is basically just a subwindow which is able to perform http queries. You just have to set the "src" attribute of your iframe element value to the right url.

$("iframe").attr("src",'proxy.php?page=' + page + ' #postsArea');
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your help but I have one problem. The iframe is displaying the whole webpage and is just scrolling down to '#postsArea'. I just want to display '#postsArea' only. I hope you can help.
This involves scraping the page you are querying. You could do it server-side in proxy.php or client-side using jQuery in an ajax request (but the iframe won't be of much use there since it's suited for displaying a complete html page, not just a single element).
Could I echo 'wrap' in the iframe?

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.