Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:45:38+00:00 2026-05-22T01:45:38+00:00

I’m trying to get more familiar with HTML5. I am an experienced programmer, but

  • 0

I’m trying to get more familiar with HTML5. I am an experienced programmer, but a javascript neophyte. I’ve written some code to getCurrentPosition (which results in an async callback when the position is fixed). Here’s the code (I already tested for, and got a positive response on, support for geolocation on this platform):

 function tryGeo() {
     document.write("asking for location <br>");
     try {
       navigator.geolocation.getCurrentPosition(savePos);
   } catch (e) {
     document.write("Excpn in asking for location <br>");
   }
     document.write("have asked for location <br>");
}

When that code runs, it pops up the permission request window or dialog. I grant permission. This is on Firefox 3.6.8 on MacOS 10.6.7.

Some time later, the callback to savePos() happens (when the position is known):

function savePos(pos) {
   lat = pos.coords.latitude;
   lon = pos.coords.longitude;
   document.write("have got location lat " +lat+ ", lon " +lon+ " <br>");
}

The problem I’m having is that that document.write() moves to a new blank page. Instead, I want to add the text to the page I was rendering when I make the getCurrentPosition() request. How can I do that?

I’m probably making some trivial beginner’s error – please let me know what.

Also, links to “learn javascript for Experienced Coders” resources would be appreciated. Thaks,

Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:45:38+00:00Added an answer on May 22, 2026 at 1:45 am

    That’s just how document.write works:

    Writing to a document that has already loaded without calling document.open() will automatically perform a document.open call.

    And document.open:

    If a document exists in the target, this method clears it.

    And their example just above that note:

    // In this example, the document contents are 
    // overwritten as the document 
    // is reinitialized on open(). 
    document.write("<html><p>remove me</p></html>"); 
    document.open(); 
    // document is empty.
    

    The easiest thing to do is to have an element already on the page and then update that element’s content. So, you’d have a bit of HTML:

    <p id="you-are-here"></p>
    

    And then in the callback:

    document.getElementById('you-are-here').innerHTML = "have got location lat " + lat + ", lon " + lon;
    

    So, yeah, your trivial beginner’s error is using document.write on a document that has already loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.