473,806 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add a text in the same HTML page

Rather than opening a new window, how can I add a text (or HTML code)
in the same HTML page, in a specific location?

The code I tried is the following:

<head>
<script language="JavaS cript">
function displayText()
{ document.write( "qwertyuiop ");
}
</script>
</head>

<body>
<a href="javascrip t:displayText() ">Text</a>
</body>
Jul 20 '05 #1
4 9211
Hi,

Caroline wrote:
Rather than opening a new window, how can I add a text (or HTML code)
in the same HTML page, in a specific location?

The code I tried is the following:

<head>
<script language="JavaS cript">
function displayText()
{ document.write( "qwertyuiop ");
}
</script>
</head>

<body>
<a href="javascrip t:displayText() ">Text</a>
</body>


First, you should not use the javascript: pseudo protocol in a link.
Rather use the ONCLICK event handler, and use the HREF attribute to lead
to a page handling users without JavaScript.

<A HREF="nojs.html "
ONCLICK="displa yText();return false;">Text</A>

That said, what you try to do is not possible for a simple reason: After
the page is rendered, the document is closed. Every attempt to write to
this closed document will reset it fully, and erase everything on the
page (including the script currently being executed).

So you will end up with a blank page with the text "qwertyuiop " on it.

YOu will need to store the document content to some place (or to have a
way to recreate/access it), add the text to this String and then write
the whole document back using document.write( ).

Note also that after you're done writing, you should close the document
with document.close( )

Hope that helps,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #2
Hi again,

Caroline wrote:
Rather than opening a new window, how can I add a text (or HTML code)
in the same HTML page, in a specific location?

The code I tried is the following:

<head>
<script language="JavaS cript">
function displayText()
{ document.write( "qwertyuiop ");
}
</script>
</head>

<body>
<a href="javascrip t:displayText() ">Text</a>
</body>


Forgot to add that you also can use the DOM Level 2 to access the text
node you want to modify. However, I am not sure if this is soemthing you
want/can do (it only works on the newest browsers and requires some
programming knowledge).

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #3
<div id="selection" class="par3"></div>
<div id="compteurs" class="par3"></div>
document.getEle mentById('selec tion').innerHTM L = "Sélection auteur : ["
+ VU + "]"

définissez des calques <div> puis utilisez la propiétés innerHTML

Caroline a écrit:
Rather than opening a new window, how can I add a text (or HTML code)
in the same HTML page, in a specific location?

The code I tried is the following:

<head>
<script language="JavaS cript">
function displayText()
{ document.write( "qwertyuiop ");
}
</script>
</head>

<body>
<a href="javascrip t:displayText() ">Text</a>
</body>


Jul 20 '05 #4
My utilitarian view of things:

"Caroline" <pl***@letsdoth atagain.com> wrote in message news:da******** *************** ***@posting.goo gle.com...
Thank you Laurent and Guy for your quick replies;
However, for didactive purposes, I would like to understand the details:
- What is wrong with the javascript: pseudo protocol in a link?
If you have this and a browser without javascript (or javascript
turned off) will have no idea what to do with the link. Thererfore,
even if you are coding for javascript, it is good general practise
to use onClick.
- what is 'return false;' used for excactly?
return false tells the browser to stop doing what it would
normally do in handling the event. In the case of a link,
it would tend to follow the link, but the "return false;" should
suppress this tendancy.
- What do you mean exactly by 'use the DOM Level 2 to access the text
node you want to modify?'

This is not your exact answer but an indication:
In early browser history people tended to view a page as
basically text that you marked up for display.
More recent browsers acknowledge that a document
is actually a graph where each all of the pieces of the
document are nodes in the graph with all sorts of
attributes that determine how the pieces display and
what can happen to/with them.
'use DOM Level 2' means to basically acknowledge
this view and explicitly operate on nodes (as opposed
to spewing HTML (with .innerHTML, say) and leaving
the browser to implicitly create the nodes) by using
constructs provided for this purpose
(such as document.create Element or
document.create TextNode and insertBefore).

Csaba Gabor from New York
Thank you

Caroline

Jul 20 '05 #5

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

Similar topics

3
6171
by: Randell D. | last post by:
Folks, I'm still learning javascript - I've invested in a couple of books and reading online as much as possible. I'm pretty sure what I am suggesting is possible though I'm trying to weigh up the faults that might go with the suggestion... all opinions welcome. My question: I have a list of links that go to pages that have a similar layout. Could I have a text swap, similar to what I've seen with image swaps (or an image switch)...
1
3834
by: Scott Navarre | last post by:
Hello, I have noticed that when using JavaScript to create a page, the sizes of the text input form elements come out bigger than the size I am trying to set them to. I don't know if it matters, but I am using IE6... For example: if I create a text input with a size of "1" using straight HTML, and then type into it, I can see 2 characters at a time. But when I use JavaScript's 'document.write()' function to create the same text...
4
3434
by: frogman042 | last post by:
My daughter is playing around trying to learn JavaScript and she wrote a small program that prints out a message in increasing and decreasing font size and color changes. She is using document write and it works fine until she puts it into a function and then calls the function from a button with onClick. This also seems to work OK, with the exception that the page is cleared, and the curser changes (and stays) as an hourglass. In...
16
3485
by: Woodmon | last post by:
I want to flow text in an "irregular" column on the left and place a large image at the top of an "irregular" column to the right. Then after the bottom of the large image I want the text column on the left to expand part way to the right, but not all the way to the right, as I want a smaller image on the right. Then this will continue to the bottom of the page. The text needs to flow down in the left column. And the right edge of the...
3
4214
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a top level <divthen I can place it with CSS attribute 'left:', but this is a fixed offset. Is it possible to have a <divcentered in the browser window? 2. Verticle centering in <div>
13
4251
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them from the html page (replace the words in the html page with blank space) I'm new to python and could use a little push in the right direction, any ideas on how to implement this? Thanks!
13
31438
by: =?Utf-8?B?S2VzdGZpZWxk?= | last post by:
Hi Our company has a .Net web service that, when called via asp.net web pages across our network works 100%! The problem is that when we try and call the web service from a remote machine, one outside of our domain, we get the error.. ** Client found response content type of 'text/html; charset=Windows-1252', but expected 'text/xml' **. We can discover the web service by typing in the url of the asmx so we know the server can 'see' it...
1
3454
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know elisp, first take a gander at Emacs Lisp Basics. HTML version with links and colors is at: http://xahlee.org/emacs/elisp_text_processing.html
1
4229
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
0
2878
by: chandrasekhar | last post by:
Hi I have developed a web page with some controls. I put all of them in session variables. I passed this values in the page. When an user enter some data in form fields and click the buttton , these values are displaying in next page.after displaying in next page, when click back button to see my entered values for change , no values are in the form fields. the fields are empty .I tried with enable view state=true in controls and at the...
0
9719
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
10366
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
10371
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
10110
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...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.