User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,745 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 5007 | Replies: 4
Reply
Join Date: May 2004
Posts: 251
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Loading External Website pages using ajax

  #1  
Nov 13th, 2007
I am trying to a page load an external website's page within a div, but it's just not working....

Anyone got any ideas?

I do know it's possible:
http://orangoo.com/labs/GreyBox/ -- loads google.com in a popup


Here's my code
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="s1/style.css" type="text/css" rel="stylesheet">
<link href="style.css" type="text/css" rel="stylesheet">


<script type="text/javascript">

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){

	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	{
		document.getElementById(containerid).innerHTML=page_request.responseText;
	}
	else
	{
		document.getElementById(containerid).innerHTML="<center><img src='load.gif' /><br>"+ page_request.statusText +"</center>";
	}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

</script>


</head>

<body onload="javascript:ajaxpage('http://www.google.com/','RESX'); ">

<div id="container">
	<div id="RESX">
	
	<div>
</div>

</body>

</html>
See what you can, remember what you need

Fourzon | Earn via Coding
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,604
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 119
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Loading External Website pages using ajax

  #2  
Nov 15th, 2007
You have at least 3 troubles there:

1. Possible copyright law violation if you don't have permission to use the materials.

2. A security violation. All files for a given page must usually come from the same server. Unless the user and the ISP severely reduce their security settings, anything else is suspected as malicious code by the security features.

3. Windows and frames are made to contain web pages. Div tags are not. You will have to strip the file to only some inner-body content to display it in a div. A popup is a window, not a div.
Last edited by MidiMagic : Nov 15th, 2007 at 2:45 am.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: May 2004
Posts: 251
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Loading External Website pages using ajax

  #3  
Nov 22nd, 2007
The script came from a tutorial site and I kept the copyright notice (says it can be used as such)

Guess I found out about the security part.

Any ideas on how to modify a page's content after it is loaded into an iframe? or at least get a portion of the page loaded in the iframe?
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Join Date: Jan 2007
Posts: 2,604
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 119
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Loading External Website pages using ajax

  #4  
Nov 23rd, 2007
The security setting usually causing the block is of the form "disallow content from multiple sites."
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: May 2004
Posts: 251
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Loading External Website pages using ajax

  #5  
Nov 25th, 2007
Thank you. Seems it's a standard across browsers not to allow scripts from different domains to interact.

Here is a link I found interesting:
http://www.dyn-web.com/dhtml/iframes/
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 5:09 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC