Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

iFrame questions (HTML, JavaScript, etc)

Posted on 2011-03-19
7
Medium Priority
?
285 Views
Last Modified: 2012-06-21
Hello Experts,

Are there ways to manipulate iFrame tags so the focus is on a specifc area of a web page, and *not* the top-left corner by default?

0
Comment
Question by:RobWellsMc
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 10

Expert Comment

by:MiniDevo
ID: 35172853
There are multiple ways, including CSS, etc. Most iFrame examples should provide help;
http://friendlybit.com/css/frames-or-iframes-with-css/
0
 

Author Comment

by:RobWellsMc
ID: 35172882
Thanks MiniDevo - unfort the webpage you provide doesn't offer ways to manipulate an iframe, or alternative ways (CSS, jQuery, etc) to do exactly what an iFrame does which is to pull in web content from other pages.

If you know of websites that provide this info, then great!!!
0
 
LVL 10

Expert Comment

by:MiniDevo
ID: 35172912
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
jtwcs earned 1000 total points
ID: 35174217
0
 

Assisted Solution

by:NetGD
NetGD earned 1000 total points
ID: 35176635
Hi,

Unfortunately it is not possible to set the scroll position of an iframe if you are loading a page that is on a different domain which is out of your control. This is a security feature of JavaScript that is illustrated in the following quote:

Now, javascript has a limitation - it can't access the document properties of pages which do not share the same domain as the parent page. Why? Because it will cause a security issue (known as cross domain security) and hence browsers do not allow that and if we try to access, it does not execute and gives a warning: Permission denied for <localhost:8080 [our page]> to get property HTMLDocument.body from <http://www.google.co.in [the external domain site]>.¹

As the previous quote shares with us, interacting with the iframe is not allowed when the domain is different from that of the parent page, or the page that the iframe resides on.

The good news is that I have come across a workaround that is fairly simple. The idea is to make the iframe as big as the webpage itself. Then wrap the iframe with a div that has an overflow set to “scroll.” Now this div will act as a layer mask with its own scroll bar, hiding the excess iframe behind it. Since the scrollbar of the div will be in your control, you can then scroll through the div to reveal parts of the elongated iframe.

Here is my own example below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Iframe Test</title>
<script type="text/javascript">
function myscroll()
{
	var obj = document.getElementById("wrapper");
	
	obj.scrollTop = 400;
}
</script>
<style type="text/css">
#wrapper {border:1px solid #000;display:block;width:1200px;height:500px;overflow:scroll;}
#loadedpage {width:1180px;height:3500px;}
</style>
</head>

<body onload="javascript:myscroll();">
<div id="wrapper">
<iframe id="loadedpage" src="http://www.amazon.com/" frameborder="0" scrolling="no"></iframe>
</div>
</body>
</html>

Open in new window

* Please note that I have removed the scrolling function of the iframe in my code to avoid double scrollbars. I have also removed the border to avoid an inner border, but also, since I am able to add it back onto the div through css if I wish.


I hope this makes sense,

NetGD



Sources:
¹ Quote was taken from Prakash Khanchandani ‘s post on http://www.liferay.com/community/forums/-/message_boards/message/7890856;jsessionid=C89925D99A8108601D4B0E6C0D1C9544.node-1
0
 

Expert Comment

by:NetGD
ID: 35176669
I’m sorry, I forgot to include the fact that you can also use "scrollLeft" in the JavaScript in the same fashion that I used scrollTop above, in order to scroll horizontally.
0
 

Author Closing Comment

by:RobWellsMc
ID: 35212466
Perfect, thanks!!!
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

715 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