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 6010247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:05:20+00:00 2026-05-23T02:05:20+00:00

I am in the process of making a bookmarklet that pops up a div

  • 0

I am in the process of making a bookmarklet that pops up a div with various things in it… when you click on the link to open the bookmarklet twice, two bookmarklets pop up. how do I prevent this from happening?

index.html:

<html>
<head>
<title>Bookmarklet Home Page</title>
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<a href="javascript:(function(){code=document.createElement('SCRIPT');code.type='text/javascript';code.src='code.js';document.getElementsByTagName('head')[0].appendChild(code)})();">click here</a>
</body>
</html>

code.js:

function toggle_bookmarklet() {
    bookmarklet = document.getElementById("bookmarklet");
    if (bookmarklet.style.display == "none") {
        bookmarklet.style.display = "";
    }
    else {
        bookmarklet.style.display = "none";
    }
}
div = document.createElement("div");
div.id = "bookmarklet";
div.style.margin = "auto";
div.style.position = "fixed";
content = "";
content += "<a href='javascript:void(0);'><div id='xbutton' onClick='javascript:toggle_bookmarklet();'>x</div></a>";
div.innerHTML = content;
document.body.appendChild(div);
  • 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-23T02:05:20+00:00Added an answer on May 23, 2026 at 2:05 am

    Just check for the existence of div before creating it.

    var div = document.getElementById("bookmarklet");
    if (!div)
    {
        div = document.createElement("div");
        div.id = "bookmarklet";
        div.style.margin = "auto";
        div.style.position = "fixed";
    }
    

    Also, since you already have a global reference to div, you don’t need to search for it by id in toggle_bookmarklet. You can just reference div. I’d try to choose a more unique name though, so as to avoid running in to naming collisions.

    Edit: For that matter, if you are going to use a global variable, you can simplify further. Don’t even bother giving it an id, just use the global reference:

    function toggle_bookmarklet() {
        bookmarkletEl.style.display = bookmarkletEl.style.display == "none" ? "" : "none";
    }
    if (!window.bookmarkletEl) {
        var bookmarkletEl = ddocument.createElement("div");
        bookmarkletEl.style.margin = "auto";
        bookmarkletEl.style.position = "fixed";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of making a website that involves a shopping cart.
I'm in the process of making some improvements to a live Drupal site that's
I am making form application, that also runs a console process on different thread.
Alright, I'm in the process of making a C# application that uses an API
I'm in the process of making some changes to a library that I'm using.
I'm in the process of making an Android application that creates a new file
I'm in the process of making a system for a client that manages data
Right now I'm in the process of making an app that streams video from
I'm in the process of making wordpress plugin using PHP. The objective is that
I am in the process of making a small program that reads a file,

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.