How do I retrieve a URL into a variable?

M

McKirahan

Tom Szabo said:
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>
 
T

Tom Szabo

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
 
T

Tom Szabo

Michael Winter said:
[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
 
B

Berislav Lopac

Tom said:
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
 
M

McKirahan

Tom Szabo said:
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>
 
M

McKirahan

McKirahan said:
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>
 
T

Tom Szabo

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
 
D

Dr John Stockton

JRS: In article <ScKmd.98763$HA.57358@attbi_s01>, dated Wed, 17 Nov
2004 15:35:14, seen in McKirahan
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top