fullscreen iframe from parent window

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

fullscreen iframe from parent window

Post by Obadiah »

I have an IFrame on my site that im using to display phpexcel pages. Im using javascript to change the src attribute...I was wondering....instead of putting another link for each page and setting the target to "_blank" for users to see the full view is there a way from the parent page to switch whatever the src is of the iframe and set the target to blank...that way its like a "veiw full screen" for the iframe
jbulaswad
Forum Newbie
Posts: 14
Joined: Tue Mar 30, 2010 2:37 pm
Location: Detroit, Michigan, USA

Re: fullscreen iframe from parent window

Post by jbulaswad »

Obadiah,

If you run a window.open in JavaScript with the IFrame's source as the first parameter you will open a new window to that URL. See the following code for an example:

Code: Select all

<html>
	<head>
		<title>IFrame in New Window</title>
		<script type="text/javascript">
			/**
			 * Opens the iframe in a new window
			 */
			function runFullscreen() { 
				var objFrame = document.getElementById('myIFrame');
				window.open(objFrame.src);
			}
		</script>
	</head>
	<body>
		<button type="button" onclick="runFullscreen();">Fullscreen</button>
		<br/>
		<iframe id="myIFrame" src="http://www.google.com" style="width: 100%; height: 300px;" />
	</body>
</html>
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: fullscreen iframe from parent window

Post by kaszu »

As I understood you want to open iframe content in parent window using a link in iframe, if so:

Code: Select all

<a href="http://www.google.com" target="_parent">Open in parent</a>

<!-- or using javascript -->

<script type="text/javascript">
    parent.window.location = "http://www.google.com";
</script>
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

**fixed*Re: fullscreen iframe from parent window*fixed**

Post by Obadiah »

jbulaswad wrote:Obadiah,

If you run a window.open in JavaScript with the IFrame's source as the first parameter you will open a new window to that URL. See the following code for an example:

Code: Select all

<html>
	<head>
		<title>IFrame in New Window</title>
		<script type="text/javascript">
			/**
			 * Opens the iframe in a new window
			 */
			function runFullscreen() { 
				var objFrame = document.getElementById('myIFrame');
				window.open(objFrame.src);
			}
		</script>
	</head>
	<body>
		<button type="button" onclick="runFullscreen();">Fullscreen</button>
		<br/>
		<iframe id="myIFrame" src="http://www.google.com" style="width: 100%; height: 300px;" />
	</body>
</html>
thanks bro...this here fit my needs perfectly... :drunk:
Post Reply