Solved

Changing the iframe content with jQuery

Posted on 2009-05-18
3
5,110 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

735 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