/    Sign up×
Community /Pin to ProfileBookmark

Parsing source of a link? very Newbie

Is it possible to get the source code of a webpage and put it into a variable using Javascript? Here’s a simplification of what i want to be able to do:

[code]
<html>
<body>
<script type=”text/javascript”>

var newText = sourceCodeOf(“http://www.google.com”)

document.write(newText.length)
</script>
</body>
</html>
[/code]

If it is possible to do this, how might the sourceCodeOf function work?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinDec 27.2005 — I'm sure there is but the only way I can think of now, is to have a function that saves the page and then a function that reads the saved page as raw text and not parse it.
Copy linkTweet thisAlerts:
@SteveireauthorJan 04.2006 — How would a function save the page?
Copy linkTweet thisAlerts:
@felgallJan 04.2006 — Javascript has no read and write functions so you will need to look at a server side language.
Copy linkTweet thisAlerts:
@CharlesJan 04.2006 — There are some tricky ways to do this - you load the document in some other Window - but JavaScript has built in certain security restrictions that will not let you monkey with somebody else's page.
×

Success!

Help @Steveire 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.18,
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,
)...