Solved

Changing the iframe content with jQuery

Posted on 2009-05-18
3
5,113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

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
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 Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

617 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