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

  • Home
  • SEARCH
  • 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 123523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:18:00+00:00 2026-05-11T04:18:00+00:00

I want to give a minimal js code to random websites so that they

  • 0

I want to give a minimal js code to random websites so that they can add a widget.

The code needs to run after the main page loads and include a parameter with the domain name. ( I don’t want to hardcode it)

One option is to add this code just before the </body> (so It will run after the page loads):

<script type='text/javascript' id='widget_script'>       document.getElementById('widget_script').src=location.protocol.toLowerCase()+'//mywebsite.com/?u='+encodeURIComponent(window.location.host);         </script> 

This works in IE but not in Firefox. I see with Firebug that the src property is created correctly but the script from my site is not loaded.

My question is : what is the best way to do that ? (preferably by putting minimal lines on the header part.)

To further clarify the question: If I put a script on the header part, how do I make it run after it is loaded and the main page is loaded? If I use onload event in my script I may miss it because it may load after the onload event was fired.

  • 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. 2026-05-11T04:18:01+00:00Added an answer on May 11, 2026 at 4:18 am

    You probably want to be implementing the non-blocking script technique. Essentially instead of modifying the src of a script, you’re going to create and append a whole new script element.

    Good write up here and there are standard ways to do this in YUI and jQuery. It’s quite straightforward with only one gotcha which is well understood (and documented at that link).

    Oh and this:

    One option is to add this code just before the </body> (so It will run after the page loads):

    …is not technically true: you’re just making your script the last thing in the loading order.

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

Sidebar

Related Questions

I have a table that contains tasks and I want to give these an
I want to give credit to all open source libraries we use in our
I want to give Windows Server 2008 a try as a .NET developer and
I want to give a link to a postscript file, but first I want
Effectively I want to give numeric scores to alphabetic grades and sum them. In
i have a wordpress blog and want to give people the same user experience
What I want to achieve is this. I want to give the user the
I have an Asp.net Mvc site where I want to give a separate access
I'm writing an intranet application for a client and I want to give them
I've got a script that pulls text from a Web server. I want to

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.