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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:20:04+00:00 2026-05-13T08:20:04+00:00

Ok, the point is having a bookmarklet load an external js that creates jquery,

  • 0

Ok, the point is having a bookmarklet load an external js that creates jquery, jquery-ui and a css file on the current web-page, with everything being done cross-domain. For some reason by the time the jquery code runs, dialog() function which is included in jquery-ui does not exist. My guess is that jquery is executing the code before the external scripts load.

Please help!

 function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

loadjscssfile("http://localhost/js/jquery-1.3.2.min.js", "js") //dynamically load and add this .js file
loadjscssfile("http://localhost/js/jquery-ui-1.7.2.custom.min.js", "js") //dynamically load "javascript.php" as a JavaScript file
loadjscssfile("http://localhost/css/redmond/jquery-ui-1.7.2.custom.css", "css") //dynamically load and add this .css file

$(document).ready(function() {
    var title = document.title;
    var location = document.location;
    var documentInfo = "url="+location+"&title="+title;


    div = $("<div id=dialog name=dialog>").html("<img src='http://localhost/ajax-loader.gif' alt='loader' style='padding-left:15px;'/>");

    $("body").prepend(div);
    $("#dialog").dialog();


    var script = $.ajax({url: "http://localhost/parse.php", data: documentInfo, async: false}).responseText;
    $("#dialog").html(script);


});
  • 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-13T08:20:04+00:00Added an answer on May 13, 2026 at 8:20 am

    You’re already lucky that your script doesn’t crash while calling $ function in $(document) 🙂

    Here is an example.

    test.js:

    function sleep(milliseconds)
    {
        var end = new Date().getTime() + milliseconds;
    
        while (new Date().getTime() < end);
    
        document.write('external script executed<br/>');
    }
    
    sleep(3000);
    

    test.html

    <html>
    <head>
        <title>test</title>
        <script type="text/javascript">
            var fileref=document.createElement('script');
            fileref.setAttribute("type","text/javascript");
            fileref.setAttribute("src", "test.js");
            document.getElementsByTagName("head")[0].appendChild(fileref)
    
            document.write('page script executed<br/>');
        </script>
    </head>
    <body>
    </body>
    </html>
    

    test.html loads test.js before writing to the document. If you expect the result to be:

    external script executed

    page script executed

    … then you’re wrong.

    When you append a <script> element to the <head> of your page, the appendChild() function returns immediatly after the element is added, it doesn’t wait for your script to be fully loaded. In the example above the output will be:

    page script executed

    external script executed

    That’s the reason why I said that you’re lucky to be able to use jQuery at a time you wan’t be sure it’s fully loaded.

    A workaround to this problem would be to append your $(document).ready(...); as a script to the <head> of your document. You could expect that a normal browser – if you see what I mean – would load and execute the scripts in the order you added them to your page.

        var pageScript = document.createElement('script');
        pageScript.setAttribute("type", "text/javascript");
        var pageScriptSource = document.createTextNode("document.write('page script executed<br/>');");
        pageScript.appendChild(pageScriptSource);
        document.getElementsByTagName("head")[0].appendChild(pageScript);
    

    Tested with FF and IE. Works in FF…

    It’s not a complete solution, but I don’t have time (and don’t want) to find a hack for IE 😉

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

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer always manage yourself the rounding, don't let the system handle… May 13, 2026 at 5:43 pm
  • Editorial Team
    Editorial Team added an answer You can make a functional data structure out of lambdas.… May 13, 2026 at 5:43 pm
  • Editorial Team
    Editorial Team added an answer jQuery 1.4 was updated to use the PHP syntax for… May 13, 2026 at 5:43 pm

Related Questions

I often run into the situation where I want to disable some code while
My game application is having a timer(starting from 0:00 then increases) when it is
My app uses SSL to communicate securely with a server and it's having trouble
Ok, I was eagerly awaiting the release of subsonic 3.0 to use as my
I am working on a desktop application in PyGTK and seem to be bumping

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.