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!

Accessing source code from different domain 1

Status
Not open for further replies.

simonchristieis

Programmer
Jan 10, 2002
1,144
GB
I would like to access the source code of another site, on another domain, using javascript, has anyone found a way round the 'security' restrictions preventing this?

Currently I have a frame set and can't get past the access denied error
 
I haven't explored this in any depth, but as a starting point, you might want to check out the 'InternetExplorer.Application' ActiveX object - something like this:

Code:
var ieObj = new ActiveXObject('InternetExplorer.Application');
ieObj.navigate('[URL unfurl="true"]http://www.google.com');[/URL]

Hope this helps,
Dan
 
In IE4(?)+ you can try using an .hta (HTML Application) file. This is only a viable solution in limited situations, since the browser forces you to download or open the file, much like an EXE. So it will work well for a corporate intranet app, but probably not for public internet consumption (unless the users already trust you). If you do choose this route, you can find more information about it Introduction to HTML Applications (HTAs). See specifically The Power of Trust: HTAs and Security.

Hope this helps,

jared@eae.net -
 
I know there's a way to get around it because I've been toying with the idea lately too. I have another domain loading in an IFRAME on one of my pages and I attempt to display the status text of the IFRAME in a DIV element on my page. Of course I get the Access Denied error, but interestingly enough, when I redirect the IFRAME to about:blank and then to any other page on the internet, the status text from the page in question loads into the DIV element. Seems to me the security is disabled just long enough when you leave the page for you to extract information from it. That being said, it's feasible that you could load a site (let's say Google) into an IFRAME. Then redirect the IFRAME to about:blank while a loop is running and constantly trying to get the image count from Google's main page. IE:
Code:
onload = init;

function init() {
   imgCount = myIFRAME.document.images.length;
   myDiv.innerText = imgCount;
   setTimeout("init()",10);
}
So the above code is repeatedly attempting to access the IFRAME and return how many images are on the page it has loaded (Google). When the page is redirected to about:blank, it might return the correct amount of images from Google. If not, redirecting the IFRAME to any random site might still return the amount of images from Google. Sounds odd, but mess around with it and you might discover a work-around. This was tested on IE6 by the way.
 
I can access the child windows href, but can't run javascript there.

something like:

javascript:alert(document.body.innerHTML)

????

there is a way round this - there must be - I know I could solve teh problem by tracking and reading temporary internet files, but dont want to go this way
 
Once again - Dan has solved a problem for me.

Another star for Dan, I won't post the code that I've created because of the security implications within it, but thanks to all that have posted.

Simon
 

Good to see you got there in the end. I couldn't work it out originally (I kept getting access errors), but realised you had to wait until the document had loaded (Busy == false) before you could do anything.

Dan
 
I simple used a do while loop till that page had loaded but all working great now.

Thanks again

In future I'll try and make it a bit more difficult for you.

9^)

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top