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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:20:50+00:00 2026-06-06T21:20:50+00:00

On a page I have an iframe. In this iframe is a collection of

  • 0

On a page I have an iframe. In this iframe is a collection of items that I need to be sortable. All of the Javascript is being run on the parent page. I can access the list in the iframe document and create the sortable by using context:

var ifrDoc = $( '#iframe' ).contents();

$( '.sortable', ifrDoc ).sortable( { cursor: 'move' } );

However, when trying to actually sort the items, I’m getting some aberrant behavior. As soon as an item is clicked on, the target of the script changes to the outer document. If you move the mouse off of the iframe, you can move the item around and drop it back by clicking, but you can not interact with it within the iframe.

Example: http://robertadamray.com/sortable-test.html

So, is there a way to achieve what I want to do – preferably without having to go hacking around in jQuery UI code?

  • 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-06-06T21:20:52+00:00Added an answer on June 6, 2026 at 9:20 pm

    Dynamically add jQuery and jQuery UI to the iframe (demo):

    $('iframe')
        .load(function() {
            var win = this.contentWindow,
                doc = win.document,
                body = doc.body,
                jQueryLoaded = false,
                jQuery;
    
            function loadJQueryUI() {
                body.removeChild(jQuery);
                jQuery = null;
    
                win.jQuery.ajax({
                    url: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js',
                    dataType: 'script',
                    cache: true,
                    success: function () {
                        win.jQuery('.sortable').sortable({ cursor: 'move' });
                    }
                });
            }
    
            jQuery = doc.createElement('script');
    
            // based on https://gist.github.com/getify/603980
            jQuery.onload = jQuery.onreadystatechange = function () {
                if ((jQuery.readyState && jQuery.readyState !== 'complete' && jQuery.readyState !== 'loaded') || jQueryLoaded) {
                    return false;
                }
                jQuery.onload = jQuery.onreadystatechange = null;
                jQueryLoaded = true;
                loadJQueryUI();
            };
    
            jQuery.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
            body.appendChild(jQuery);
        })
        .prop('src', 'iframe-test.html');
    

    ​
    Update: Andrew Ingram is correct that jQuery UI holds and uses references to window and document for the page to which jQuery UI was loaded. By loading jQuery / jQuery UI into the iframe, it has the correct references (for the iframe, rather than the outer document) and works as expected.


    Update 2: The original code snippet had a subtle issue: the execution order of dynamic script tags isn’t guaranteed. I’ve updated it so that jQuery UI is loaded after jQuery is ready.

    I also incorporated getify’s code to load LABjs dynamically, so that no polling is necessary.

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

Sidebar

Related Questions

i know i can have iframe in a html page, say parent.htm, and i
I have an iframe on a page that I need to initially have a
I have a page we can call parent.php . In this page I have
According to this answer: Invoking JavaScript code in an iframe from the parent page
I have a page that contains a dynamically loaded <iframe> . This iframe contains
I have a page in html (parent page) that have inside an iframe. When
I have a page with another html page in iframe. In this iframe, i
I have a web page that has a DIV and an IFRAME. When a
I have iframe on a page, the iframe and the parent page are in
i have a iframe and it is linked to pictures.html and on this page

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.