Solved

iFrame questions (HTML, JavaScript, etc)

Posted on 2011-03-19
7
271 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 10

Accepted Solution

by:
jtwcs earned 250 total points
ID: 35174217
0
 

Assisted Solution

by:NetGD
NetGD earned 250 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
How to strip HTML from this JS code using regex 29 46
Change background images after 5 seconds. 12 48
Checkbox changes display when resizing window 8 26
css messed up 8 30
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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…

710 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