peipei
peipei

Reputation: 1497

How to iframe part of webpage from server A to server B?

I have a web page from server A, I want to only <iframe> the form on it to server B. The form resides on the top right corner of this web page, width: 252px; height: 436px; Is this JavaScript can do it? or just simple HTML and CSS work?

For example, I put this script on server B, it will show top left corner of webpage: http://www.example.com/example.html

<html>
<head>
<title></title>

<style type="text/css">

</style>

</head>
<body>
<div id="container">
<iframe src="http://www.example.com/example.html" scrolling="no" width="252" height="436"></iframe>
</div>
</body>

Upvotes: 0

Views: 870

Answers (1)

Marc B
Marc B

Reputation: 360562

iframes are a way of embedding the entirety of some other webpage within the body of the current page. The frame is part of the 'host' document, while the content it's loading is a completely separate document. It's no different than having two separate browser windows open.

If server B cannot be told to serve up only the form you want, then you cannot use an iframe to display just the form. You'll just get the entire page. You'd have to fetch the page separately, extract the relevant bits of HTML, and insert just that snippet.

This can also not be done via javascript, as you'd be attempting to load a resource from another page, running into the same-origin security policies.

Upvotes: 3

Related Questions