Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to affect a webpage within a webpage 1

Status
Not open for further replies.

hitsuin

Vendor
Aug 23, 2010
24
GB
Hello everyone, I wanted to know how JavaScript can be use to affect a webpage that displayed within another webpage.

Code:
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
  <head>
	<title></title>
	<meta http-equiv="Content-Type"
	content="text/html; charset=utf-8" />
  </head>
  <body>
    <object data=[URL unfurl="true"]http://www.ObjectData.com[/URL] width="1000" height="400"> <embed src=[URL unfurl="true"]http://www.ObjectData.com[/URL] width="1000" height="400"> </embed> Error: Embedded data could not be displayed. </object>
</body>
</html>

For example assuming that the code below is objectdata.com how would I put the "theDiv.innerHTML = theText;" into the above code to access the bottom one.

Code:
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">

<script type="text/javascript">

document.onkeyup = function( evt )
{ 
 if( ( window.event || evt ).keyCode == 13 ) 
  DisplayText(); 
}
function DisplayText() {

            var theText = document.getElementById('textbox').value;
            var theDiv = document.getElementById('targetDiv');
            theDiv.innerHTML = theText;
        }
</script>

</head>
<body>
<div><p id="targetDiv" ></p></div>
<form action="" onsubmit = 'return false'>
<p><input id="textbox" maxLength=6 size=6 name=textbox  ></p>

<p><input value= "Display" onclick="DisplayText();" type="button"></p></form>

</body></html>
 
As far as I know, unless both sites are hosted on the same domain (or subdomain thereof), or you have access to the source of the inner page (whether directly or via a third party), then you will not be able to do this with client-side scripting alone due to security restrictions put in place by most web browsers.

So:

- Are the files hosted on the same domain or subdomain thereof?

- Do you have access to modify the inner page's HTML (directly or indirectly)?

If the answer to those questions is "No", then I think you may be out of luck with a purely client-side solution, so you may want to consider server-side scraping instead.

Hope this helps,

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
I can't believe I didnt thank you for letting me know. Its a thing I try to do. Thanks for telling me.
 
Apparently there is a way via proxy servers and Ajax - search for Ajax on this forum. But don't expect it to be simple. I cried-off at the first hurdle.

Client-side JavaScript cannot access cross-domain content. I have tried. Server-side can.

The way I read such content is to run VBA in Excel and inspect the innerHTML but that is for personal use - like Eurosport TV schedules filtering for specific words like "Dakar" (running for the next 14 days).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top