Advanced Search

Results 1 to 5 of 5

Thread: Javascript Write To Website Without Clearing All Data

  1. #1
    Join Date
    Jul 2011
    Posts
    53
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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,621
    Thanks
    63
    Thanked 516 Times in 502 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.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #3
    Join Date
    Jul 2011
    Posts
    53
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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,297
    Thanks
    28
    Thanked 135 Times in 130 Posts
    Blog Entries
    28

    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,154
    Thanks
    260
    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
  •