Solved

Changing the iframe content with jQuery

Posted on 2009-05-18
3
5,097 Views
Last Modified: 2012-08-12
For having some big areas with scroll bars inside my web page, I'm willing to use an iframe. Maybe it isn't a good idea, open to suggestions in here.

I'm using the library jQuery, and I was considering to play with the iframe DOM from the parent window.

The child window(iframe) will not load an url. If is supposed to be changed (it has a really dynamic content) by the parent only.


Who do I change the iframe DOM?
What other solution do I have? (using just html and Javascript)

0
Comment
Question by:oleber
3 Comments
 
LVL 5

Accepted Solution

by:
bored321 earned 500 total points
ID: 24413396
So you basically want an area with a scroll bar which you can add content to using jquery?

If so i would suggest just using a normal div with the overflow set to auto, and use a fixed size.


<div style="overflow:auto; width:400px; height:400px;"></div>

Open in new window

0
 
LVL 14

Expert Comment

by:ziffgone
ID: 24414242
Is the content to be shown in the scrolling area to be retrieved from external HTML files, like the iframe would?

If so, you can go with an idea like bored321 says:


// Scrolling area:
 

<div id="content1" style="overflow:auto; width:400px; height:400px;"></div>
 

// function jQuery to populate scrolling Div with external content:
 

function getContent(targetDiv,page){

         $.get(page,function(content){

             $(targetDiv).html(content);

         });

}
 

// Command to populate on page load:
 

$(document).ready(function(){

    getContent('#content1','/path/to/external.html');

});
 

// Linked Nav would be like this:
 

<a href="javascript:getContent('#content1','/path/to/external.html');return false;">Page 1</a>

<a href="javascript:getContent('#content2','/path/to/external2.html');return false;">Page 2</a>

Open in new window

0
 
LVL 1

Expert Comment

by:hbash
ID: 38285594
I tried the following other method:

        function getContent(targetDiv, page) {
            alert('Running getContent');

            $.get(page, function (content) {
                $(targetDiv).html(content);
            });
        };

....
....


    <div id="content1" style="overflow:auto; width:50px; height:50px;"></div>
    <a href="javascript:getContent('#content1','www.yahoo.com');return false;">Page 1</a>

Open in new window


And clicking the "Page 1" anchor did not find the div and so no action or alert message.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now