Solved

Changing the iframe content with jQuery

Posted on 2009-05-18
3
5,104 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:Howard Bash
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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 …

776 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