Results 1 to 5 of 5

Thread: Javascript Write To Website Without Clearing All Data

  1. #1
    Join Date
    Jul 2011
    Posts
    54
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Javascript Write To Website Without Clearing All Data

    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!

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by M2com View Post
    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.

    Quote Originally Posted by M2com View Post
    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.

  3. #3
    Join Date
    Jul 2011
    Posts
    54
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    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.

  4. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,337
    Thanks
    30
    Thanked 137 Times in 132 Posts
    Blog Entries
    32

    Default

    As Adrian said, code is always good. Let's assume you already have this in the body of your document:
    Code:
    <body>
    Text that is already there.
    </body>
    Then if you want to add new data to the body, you could modify it like this:
    Code:
    <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:
    Code:
    <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'.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    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).
    Last edited by jscheuer1; 06-17-2013 at 12:27 AM. Reason: correct pseudo code
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Similar Threads

  1. Clearing Browser History using JavaScript
    By codeexploiter in forum JavaScript
    Replies: 23
    Last Post: 09-14-2011, 09:40 PM
  2. How to write/obtain legal documents for website
    By djr33 in forum Looking for such a script or service
    Replies: 1
    Last Post: 12-27-2009, 04:40 PM
  3. How should I write this javascript in php
    By Dennis_Gull in forum PHP
    Replies: 5
    Last Post: 04-10-2007, 05:57 AM
  4. Clearing browser cache in Javascript
    By harshaghanta in forum JavaScript
    Replies: 7
    Last Post: 12-06-2006, 04:00 AM
  5. Write Data To Another File?
    By clueless in forum JavaScript
    Replies: 0
    Last Post: 11-26-2004, 10:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •