PDA

View Full Version : Javascript Write To Website Without Clearing All Data



M2com
06-16-2013, 06:07 PM
I'm trying to create a javascript script that will will insert links and other javascript scripts into the page without overwriting the page. The main script will be in a bookmarlet (a bookmark with the url like this: javascript:blahblahscript). This can run on any page when clicked.

Thanks for your help in advanced!

traq
06-16-2013, 06:32 PM
I'm trying to create a javascript script that will will insert links and other javascript scripts into the page without overwriting the page. The main script will be in a bookmarlet (a bookmark with the url like this: javascript:blahblahscript). This can run on any page when clicked.That's great.


Thanks for your help in advanced!
...what do you need help with?

You need to explain what it is you're having problems with, and what those problems are. Code is always good, too.

M2com
06-16-2013, 07:35 PM
I'm wondering how to do that. Like could you give me a code snippet to put html/javascript/etc code onto a page without clearing the whole page.

molendijk
06-16-2013, 10:57 PM
As Adrian said, code is always good. Let's assume you already have this in the body of your document:

<body>
Text that is already there.
</body>
Then if you want to add new data to the body, you could modify it like this:

<body>
Text that is already there.
<br><div id="new_data"></div>
<a href="javascript: void(0)" onclick="document.getElementById('new_data').innerHTML='data added'; return false">add data</a>
</body>
But that's only a simple example. There are thousands of ways to add data to a file.
You are referring to 'clearing the page'. Do you have document.write in mind? That's the wrong way to do it. If you would have:

<body>
Text that is already there.
<br><div id="new_data"></div>
<a href="javascript: void(0)" onclick="document.write('data added')">add data</a>
</body>
you would clear the page before adding 'data added'.

djr33
06-16-2013, 11:22 PM
You might also want to consider document.body.appendChild(), if you're wanting to insert something new on the page (that works on any page).