469,271 Members | 1,743 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

How do I retrieve a URL into a variable?


I like to know if there is a JS function to retrieve a URL into a variable

cURL = somefunction("http://www.domain.com");

Is there something like this?

TIA,

Tom
Jul 23 '05 #1
11 15094
"Tom Szabo" <to*@intersoft.net.au> wrote in message
news:41********@dnews.tpgi.com.au...

I like to know if there is a JS function to retrieve a URL into a variable

cURL = somefunction("http://www.domain.com");

Is there something like this?

TIA,

Tom


By "retrieve a URL" do you mean of the page containing the JS?

<html>
<head>
<title>loc~href.htm</title>
<script type="text/javascript">
var url = document.location.href;
document.write(url);
</script>
</head>
<body>
</body>
</html>
Jul 23 '05 #2
On Wed, 17 Nov 2004 12:31:43 GMT, McKirahan wrote:
"Tom Szabo" <to*@intersoft.net.au> wrote in message
news:41********@dnews.tpgi.com.au...

I like to know if there is a JS function to retrieve a URL into a variable

cURL = somefunction("http://www.domain.com");
.... By "retrieve a URL" do you mean of the page containing the JS?


I suspect the OP is actually referring to retrieving the content
of another URL (than the page itself) into a JS var as text.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #3
> By "retrieve a URL" do you mean of the page containing the JS?

I could be using the wrong terminology, what I ment is to get the content of
the web page the URL pointing to....so

var "url" would contain something like:

"<html>
<head>
.....

......
/html>"

Am I making sense? sorry if still not ....

TIA,

Tom

Jul 23 '05 #4
On Wed, 17 Nov 2004 22:34:50 +1000, Tom Szabo <to*@intersoft.net.au> wrote:

[snip]
I could be using the wrong terminology, what I ment is to get the
content of the web page the URL pointing to....so


Please read the FAQ (<URL:http://jibbering.com/faq/>). Your question is
answered there.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
> >> cURL = somefunction("http://www.domain.com");
...
By "retrieve a URL" do you mean of the page containing the JS?


I suspect the OP is actually referring to retrieving the content
of another URL (than the page itself) into a JS var as text.


YES, correct, that is what I like to do...
Jul 23 '05 #6

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opshl090olx13kvk@atlantis...
On Wed, 17 Nov 2004 22:34:50 +1000, Tom Szabo <to*@intersoft.net.au> wrote:
[snip]
I could be using the wrong terminology, what I ment is to get the
content of the web page the URL pointing to....so


Please read the FAQ (<URL:http://jibbering.com/faq/>). Your question is
answered there.


Thanks for that, but I think that asi a way too complicated solution....

If there is no simpler, I can just create a new window with the URL and read
the content of the DOC if nothing better, but I do beleive thre should be a
simpler solution...?

Thanks anyway,

Tom
Jul 23 '05 #7
Tom Szabo wrote:
By "retrieve a URL" do you mean of the page containing the JS?


I could be using the wrong terminology, what I ment is to get the
content of the web page the URL pointing to....so

var "url" would contain something like:

"<html>
<head>
....

.....
/html>"

Am I making sense? sorry if still not ....

TIA,

Tom


Use XmlHttpRequest object.

Berislav
Jul 23 '05 #8
"Tom Szabo" <to*@intersoft.net.au> wrote in message
news:41********@dnews.tpgi.com.au...
> cURL = somefunction("http://www.domain.com");

...
By "retrieve a URL" do you mean of the page containing the JS?


I suspect the OP is actually referring to retrieving the content
of another URL (than the page itself) into a JS var as text.


YES, correct, that is what I like to do...

Will this help? Watch for word-wrap.

Change the value of "onclick=XML()" as necessary.

<html>
<head>
<title>XMLHTTP.htm</title>
<script type="text/vbscript">
Sub XML(strURL)
Dim strXML
strXML = strURL
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "GET", strURL, False
objXML.Send
If Err.Number = 0 And objXML.Status = 200 Then
strXML = objXML.ResponseText
strXML = Replace(strXML,"<","&lt;")
strXML = Replace(strXML,">","&gt;")
strXML = Replace(strXML,vbLf,"<br>")
End If
Set objXML = Nothing
document.write(strXML)
End Sub
</script>
</head>
<body>
<input type="button" value="Click Me!"
onclick="XML('http://www.Google.com/')">
</body>
</html>
Jul 23 '05 #9
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:ScKmd.98763$HA.57358@attbi_s01...
"Tom Szabo" <to*@intersoft.net.au> wrote in message
news:41********@dnews.tpgi.com.au...
>> cURL = somefunction("http://www.domain.com");
...
> By "retrieve a URL" do you mean of the page containing the JS?

I suspect the OP is actually referring to retrieving the content
of another URL (than the page itself) into a JS var as text.


YES, correct, that is what I like to do...

Will this help? Watch for word-wrap.

Change the value of "onclick=XML()" as necessary.


[snip]

You probably wanted the JavaScript version.

<html>
<head>
<title>Google.htm</title>
<script type="text/javascript">
function XML(strURL) {
var objXML = new ActiveXObject("Microsoft.XMLHTTP");
objXML.open("GET",strURL,false);
objXML.send();
var strXML = objXML.responseText;
strXML = strXML.replace(/</g,'&lt;');
strXML = strXML.replace(/>/g,'&gt;');
strXML = strXML.replace(/\n/g,'<br>');
document.write(strXML)
}
</script>
</head>
<body>
<input type="button" value="Click Me! (js)"
onclick="XML('http://www.Google.com/')">
</body>
</html>
Jul 23 '05 #10
You probably wanted the JavaScript version.

<html>
<head>
<title>Google.htm</title>
<script type="text/javascript">
function XML(strURL) {
var objXML = new ActiveXObject("Microsoft.XMLHTTP");
objXML.open("GET",strURL,false);
objXML.send();
var strXML = objXML.responseText;
strXML = strXML.replace(/</g,'&lt;');
strXML = strXML.replace(/>/g,'&gt;');
strXML = strXML.replace(/\n/g,'<br>');
document.write(strXML)
}
</script>
</head>
<body>
<input type="button" value="Click Me! (js)"
onclick="XML('http://www.Google.com/')">
</body>
</html>


Thanks, I will give it a go. Looks like this is is what I wanted,

Thanks again,

Tom
Jul 23 '05 #11
JRS: In article <ScKmd.98763$HA.57358@attbi_s01>, dated Wed, 17 Nov
2004 15:35:14, seen in news:comp.lang.javascript, McKirahan
<Ne**@McKirahan.com> posted :
"Tom Szabo" <to*@intersoft.net.au> wrote in message
news:41********@dnews.tpgi.com.au...
> >> cURL = somefunction("http://www.domain.com");
> ...
> > By "retrieve a URL" do you mean of the page containing the JS?
>
> I suspect the OP is actually referring to retrieving the content
> of another URL (than the page itself) into a JS var as text.
YES, correct, that is what I like to do...

Will this help? Watch for word-wrap.


Watching for word-wrap is the author's duty. Don't be slothful.

Change the value of "onclick=XML()" as necessary.

<html>
<head>
<title>XMLHTTP.htm</title>
<script type="text/vbscript">
Sub XML(strURL)
Dim strXML
strXML = strURL
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
...


Not only is this a javascript newsgroup, but it is also substantially a
group for web pages.

Therefore, since many differing OSs and browsers can be used to read Web
pages, a "solution" that works only with Microsoft systems is of limited
use, unless the OP has indicated otherwise. When a limited-use
"solution" is presented, a corresponding warning should be given. Yours
appears to be such a "solution", even in javascript.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Tammy B. | last post: by
4 posts views Thread by spiderman | last post: by
41 posts views Thread by Miguel Dias Moura | last post: by
12 posts views Thread by Phil Certain | last post: by
2 posts views Thread by Bishman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.