/    Sign up×
Community /Pin to ProfileBookmark

Opening web pages

I’ve been searching all over the internet for a function or a way to build a function that would take a URL and return a string containing the contents of the file found at that URL.

For example openPage(‘http://www.somesite.com/somepage.html‘) might return <html><head><title>Some Page</title></head><body>Some page.</body></html> in a string.

It seems like the XMLHTTPRequest should be able to do this but so far I’ve had no luck with it.

Thanks for any help.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@igvAug 01.2009 — as far as I know you cannot do cross domain XMLHttpRequest (but don't quote me on that), at least the easy way ?

I think what you trying to achieve is possible by using iframe, you just load your url in iframe and take all document html from it after it is loaded.

Let me know if you need more info on this.
Copy linkTweet thisAlerts:
@garrinauthorAug 01.2009 — Thanks, that would explain why that wasn't working. I'll try out the iframes, it shouldn't be too complicated. But I'm wondering if there is a way to make an iframe with the javascript without having to add it to the page. Something along the lines of var myFrame = new iframe;

Thanks for the help.
Copy linkTweet thisAlerts:
@igvAug 01.2009 — no, it should be added to the document, but you can add it to the end of the body with display: none, this should not affect anything on your page then
Copy linkTweet thisAlerts:
@garrinauthorAug 01.2009 — One last question, how do I get the source from the frame? I've been searching around but I can't seem to find a straight answer. I tried myFrame.document.innerHTML but it didn't work.

Thanks again for all the help.
Copy linkTweet thisAlerts:
@igvAug 01.2009 — it's different for different browsers, this should work for you
[CODE]
var frameDoc = null;

if(frame.contentDocument) {
frameDoc = frame.contentDocument;
}
else if(frame.contentWindow) {
frameDoc = frame.contentWindow.document;
}
else {
frameDoc = window.frames[frame.id].document;
}
[/CODE]


this have a little bulky syntax, but it gives you an idea, make it shorter if needed

this will give you frame document element from which you can extract source code.
Copy linkTweet thisAlerts:
@igvAug 01.2009 — forgot to say that in previous post "frame" variable is the actual frame element you created
×

Success!

Help @garrin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...