473,746 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grab Data Displayed On Other Web Page Using document.write

Perhaps I'm Googling for the wrong terms. Does anyone have links to
examples of the syntax necessary to read the HTML on another Web page when
that HTML is produced from JavaScript using the document.write( ) method?

For a simplified example, I have two Web pages. Page 1 uses JavaScript with
the following:

htmlData = "<B>This is bold text.</B>";
document.write( htmlData);

Page 1 displays in bold text:

This is bold text.

Page 2 needs to get the markup for page 1, i.e., just "<B>This is bold
text.</B>" (which includes the tags), not the JavaScript code listed above.
I've tried using the responseText property of the MSXML2.XMLHTTP. 3.0 object,
but it gives me the JavaScript used for rendering page 1, not the markup
(that's stored in the htmlData variable).

The ultimate goal is to grab the data displayed on a Web page and display
only the items needed on another Web page. I can parse the HTML based upon
the tags to target exactly the data I want. That's why I need to read the
tags.

Suggestions for other approaches are welcome. I'm the author of both Web
pages, so I have some leeway. Preference is for client-side JavaScript. I
have some experience in JavaScript, but I'm a C/Java programmer.
Cross-platform compatibility is preferred, and the majority of browsers will
be IE6. I can also run Perl scripts on the Web server, but I have little
experience with Perl, so this would be an opportunity to learn more. In
case it matters, the Web server is Apache on Linux.

Thanks.

Gunny
Jan 11 '06 #1
8 9417


'69 Camaro wrote:

For a simplified example, I have two Web pages. Page 1 uses JavaScript with
the following:

htmlData = "<B>This is bold text.</B>";
document.write( htmlData);

Page 1 displays in bold text:

This is bold text.

Page 2 needs to get the markup for page 1, i.e., just "<B>This is bold
text.</B>" (which includes the tags), not the JavaScript code listed above.
I've tried using the responseText property of the MSXML2.XMLHTTP. 3.0 object,
but it gives me the JavaScript used for rendering page 1, not the markup
(that's stored in the htmlData variable).


That script code is being executed by a browser/user agent when it
renders the HTML document so one way to access that contents with script
is to use script to automate a browser. On Windows Microsoft IE can be
automated so you use a Windows Script Host script to create an IE
instance, load a URL and then read out the innerHTML or outerHTML of an
element in the browser's document object model. Of course if you have
the complete document tree object model then I am not sure you need the
serialized markup to reparse it yourself. And you should be aware that
the browser object model will usually include both the contents created
by script and the script element itself.
That way you have a script application to be run on a system where IE is
installed and IE loads a remote URL.

Another approach might be HTTP Unit
<http://www.httpunit.or g/>
although I don't know how good their script support is and whether they
allow access to elements and/or serialized markup.

None of that however allows you to have browser-side script in one HTML
document access the DOM created by script in another HTML document. With
the same origin policy that is only possible if you have two documents
on the same server, then you can use frames or windows and use cross
frame or cross window script techniques.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 11 '06 #2
Martin Honnen wrote:
None of that however allows you to have browser-side script in one HTML
document access the DOM created by script in another HTML document. With
the same origin policy that is only possible if you have two documents
on the same server, [...]


It is still only the same second-level domain, will you recognize that?
PointedEars
Jan 11 '06 #3
"Martin Honnen" wrote in message
news:43******** *************** @newsread4.arco r-online.net...
On Windows Microsoft IE can be automated so you use a Windows Script Host
script to create an IE instance, load a URL and then read out the
innerHTML or outerHTML of an element in the browser's document object
model.
Thanks for that info. I now have an option for visitors with IE browsers.
And you should be aware that the browser object model will usually include
both the contents created by script and the script element itself.
So the contents created by the script on Web page 1 can be accessed using
the innerHTML property of the document.body element of Web page 1? If so,
does this apply just to IE or does it also apply to other common browsers,
such as Firefox, Netscape, and Opera?
Another approach might be HTTP Unit
<http://www.httpunit.or g/>
although I don't know how good their script support is and whether they
allow access to elements and/or serialized markup.
Thanks for that info. It can help with the automated testing of Web
applications which I'd recently been wondering about, so thanks for
answering another question of mine!
With the same origin policy that is only possible if you have two
documents on the same server, then you can use frames or windows and use
cross frame or cross window script techniques.


Both HTML documents are in the same subdomain on the same Web server, so I
think this satisfies the same origin policy. I've been Googling on
cross-window scripting, looking for examples of cross-window scripting
syntax, but all I've seen so far are examples that spawn a new window (which
I'd rather avoid unless I can make it invisible to the user -- which I don't
know how to do), and then write to the new window, but I need to read its
contents instead.

Do you have any links to example syntax for accessing a Web page's DOM
without spawning a new window (if this is even possible), or for hiding a
spawned window, or for reading the window's contents if my guess on the
innerHTML property of the document.body element of Web page 1 is incorrect?

Thanks.

Gunny
Jan 11 '06 #4
'69 Camaro said the following on 1/11/2006 3:45 PM:

<snip>

Do you have any links to example syntax for accessing a Web page's DOM
without spawning a new window (if this is even possible), or for hiding a
spawned window, or for reading the window's contents if my guess on the
innerHTML property of the document.body element of Web page 1 is incorrect?


If all you are wanting to do is get the contents of a page, load it in a
hidden IFrame and access it from there using the Frames collection.

window.frames['IFrameNAMEnotI D'].property

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 11 '06 #5
"Randy Webb" wrote in message news:ip******** ************@co mcast.com...
If all you are wanting to do is get the contents of a page, load it in a
hidden IFrame and access it from there using the Frames collection.

window.frames['IFrameNAMEnotI D'].property


Thanks. I'm not familiar with Frames or IFrames, but I figured out how to
create an IFrame and make it invisible. Now I'm stuck on the syntax for
trying to read the HTML produced by the document.write( ) method of the Web
page loaded into that IFrame. To give a very simplified example, say the
following Web page was loaded into the IFrame:

<HTML>
<BODY>
<SCRIPT Language = "JavaScript " TYPE = "text/javascript">
<!--
var htmlData;
htmlData = "<B>This is bold text.</B>";
document.write( htmlData);
//-->
</SCRIPT>
</BODY>
</HTML>

.. . . and I want to read the HTML produced by the document.write( ) method.
In the main window, I'd like to use something like the following:

html = window.frames['StatsFrame'].whateverGoesHe re;

.. . . where the variable, html, receives "<B>This is bold text.</B>".

Any suggestions on the correct syntax for "whateverGoesHe re"?

Thanks.

Gunny
Jan 12 '06 #6
'69 Camaro said the following on 1/11/2006 7:12 PM:
"Randy Webb" wrote in message news:ip******** ************@co mcast.com...
If all you are wanting to do is get the contents of a page, load it in a
hidden IFrame and access it from there using the Frames collection.

window.fram es['IFrameNAMEnotI D'].property

Thanks. I'm not familiar with Frames or IFrames, but I figured out how to
create an IFrame and make it invisible. Now I'm stuck on the syntax for
trying to read the HTML produced by the document.write( ) method of the Web
page loaded into that IFrame. To give a very simplified example, say the
following Web page was loaded into the IFrame:

<HTML>
<BODY>
<SCRIPT Language = "JavaScript " TYPE = "text/javascript">
<!--
var htmlData;
htmlData = "<B>This is bold text.</B>";
document.write( htmlData);
//-->
</SCRIPT>
</BODY>
</HTML>

.. . . and I want to read the HTML produced by the document.write( ) method.
In the main window, I'd like to use something like the following:

html = window.frames['StatsFrame'].whateverGoesHe re;

.. . . where the variable, html, receives "<B>This is bold text.</B>".

Any suggestions on the correct syntax for "whateverGoesHe re"?

IFrame Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<title>Form Test Page</title>
<script type="text/javascript">
var htmlData;
htmlData = "<B>This is bold text.</B>";
document.write( htmlData);
</script>
</head>
<body>
</body>
</html>

Main Page Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Frame test</title>
</head>
<body>
<iframe src="blank.html " name="myIFrame" >Test text here</iframe>
<button
onclick="alert( window.frames['myIFrame'].document.body. innerHTML)">Sho w
Title</button>
</body>
</html>

Opera 8, Firefox and IE all give me simply the HTML that was generated.
Namely, "<B>This is bold text.</B>"

So it appears the above should be close to what you want or at least
close enough to get you started on it.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 12 '06 #7
"Randy Webb" wrote in message
news:_u******** *************** *******@comcast .com...
So it appears the above should be close to what you want or at least close
enough to get you started on it.


Thank you! That gets me much closer to where I want to be. However, I'm
still trying to get over the hurdle of determining from the second Web page
what's in the the string variable used for the document.write( ) method on
the first Web page. While I gave a simplified example of the JavaScript on
my Web page, the value passed to document.write( ) is actually the value of
the property of an object, not a string literal. The object is returned
from a function that I pass variables to, and the function dynamically
creates the HTML needed to display a Web page with all of the data. For
example:

stats = getStats(uid, mid, gid, lg, crit, sUrl);
htmlData = stats.Text;
document.write( htmlData);

.. . . and the value in the stats.Text property would be the string
containing the HTML with the data and the tags I need to parse, like
"<B>This is bold text.</B>". This markup never actually appears on Web page
1, so I don't know how to read it from Web page 2 and extract only the data
I need.

Any suggestions on how to read from Web page 2 either the value stored in
htmlData or the Web page contents created by my script on Web Page 1? I've
tried using getElementByNam e( ) and getElementByID( ) to retrieve the
htmlData variable (or value) in the frame object, but I don't have the
correct syntax because it bombs.

Thanks.

Gunny
Jan 12 '06 #8
'69 Camaro said the following on 1/12/2006 10:02 AM:
"Randy Webb" wrote in message
news:_u******** *************** *******@comcast .com...
So it appears the above should be close to what you want or at least close
enough to get you started on it.

Thank you! That gets me much closer to where I want to be. However, I'm
still trying to get over the hurdle of determining from the second Web page
what's in the the string variable used for the document.write( ) method on
the first Web page. While I gave a simplified example of the JavaScript on
my Web page, the value passed to document.write( ) is actually the value of
the property of an object, not a string literal. The object is returned
from a function that I pass variables to, and the function dynamically
creates the HTML needed to display a Web page with all of the data. For
example:

stats = getStats(uid, mid, gid, lg, crit, sUrl);
htmlData = stats.Text;
document.write( htmlData);


If the name of that variable is always htmlData, then you can access it
by window.frames['IFrameNAMEnotI D'].htmlData

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9016
by: Scott | last post by:
I need help to modify the code below to pass url variables from a framset. The click to run this will be in the mainFrame. This script works well in a non-frame page. Grabs the current url variables and adds them to my url. <script type="text/javascript"> //<!]> </script>
4
2824
by: Razzbar | last post by:
I need to be able to conditionally load a remote script, using the "<script src=..." syntax. Or some other way. I've seen people writing about using the document.write method, but it's not working like I want it to. What's happening is, if I do a document.write(scriptcall), the script loads, although sometimes very slowly... (?). Any inline code is executed (I used an alert to verify that the script is loading). But all the previous...
13
9648
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
3
3600
by: Paul Thompson | last post by:
I am working with a special tool which pre-processes the page. Using document.write, I am composing the page while it is loading, so I need to force a reprocess of the page AFTER the page loads. Is there some way to do that? That is, I want the browser to essentially act as if the composed page was the original page. Here is a brief version of the page construction technique:
2
1351
by: BP | last post by:
if the input field was generated in Client-side Javascript by document.write, how to retrieve the data of the input field in code behind? Thanks
5
3142
by: arizal | last post by:
Hello everyone, i just saw the same thread below but was not able to get from it. Well the problem is in the userlist page i have a list of users on the database which i get from simple sql queries. On the same page on the side of each User i have delete link. Also inside the while Loop that runs sql and prints User Names i have some variable say $userid = $row . But I am not sure how i am going to transfer this $userid to other page when...
1
7544
by: anupamaavadutha | last post by:
hi all, iam new to javascript. i have problem calling javascript functions.iam designing a calender page.here is my code. <%@ page import='java.io.*,java.util.*,java.sql.*,javax.servlet.*,javax.servlet.http.*' session='true'%> <%@ page import='java.text.*'%> <html> <script language='javascript'> function backward() { alert("hello"); }
0
8974
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9218
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4586
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.