Solved

Changing the iframe content with jQuery

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

920 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