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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:15:11+00:00 2026-05-28T19:15:11+00:00

The function below is intended to grab/process the HTML of either a jQuery selector

  • 0

The function below is intended to grab/process the HTML of either a jQuery selector or a URL. If a URL is passed in, it generates an iframe and, after the iframe is loaded, grabs the iframe’s HTML. (Note: I’m not using external URLs, just other pages on the same site.)

The function is throwing TypeError: 'undefined' is not an object (evaluating 'myHTML.find') whenever I pass in a URL. I don’t understand why. Does anything stand out here?

1   mynamespace.html: function ( source ) {
2   // Grabs and processes the HTML of a jQuery selector or URL.
3      
4      var myHTML;
5
6         if ( $(source).is('iframe') ) {
7            // if it's an iframe, use .contents() 
8            myHTML = $(source).contents().find('html').clone();
9
10        } else if (source.indexOf('http://') === 0 ) {
11           // if it's a URL, load an iframe
12           $(document.body).append('<iframe id="printiframe" src="'+source+'"></iframe>');   
13           $('#printiframe').load(function() {
14               // once loaded, send it back into this function,
15               // where it can then be processed as an iframe
16               return mynamespace.html ('#printiframe');
17           });
18
19        } else {
20           myHTML = $(source).clone();
21        }   
22      
23        // Do stuff to the HTML here, such as myHTML.find('bla')...
24
25        return myHTML.html();
26   }
  • 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-28T19:15:12+00:00Added an answer on May 28, 2026 at 7:15 pm

    I hope you don’t mind, but I edited your question to add line numbers to the code for ease of reference rather than repeating all of the code here.

    Anyway, I believe the problem is with the else if branch starting on line 10. The sequence of execution will be:

    • Line 12 – append the iframe
    • Line 13 – make the ajax .load() request
    • Lines 18/19 – the end of the branch
    • Lines 22-24 – where you have your comment about doing stuff, at which point myHTML has not been assigned a value (hence the error you are getting)
    • Line 25 – return from the function

    Then, after the asynchronous Ajax request returns:

    • Line 16 – the body of the callback function you provided.

    This is the way asynchronous code works – no matter how fast the request, the callback won’t be called until after the other code is finished executing. The return statement on line 16 doesn’t return from your mynamespace.html() function, it returns from that callback (and nothing is paying attention to that return).

    You could try to restructure your code slightly to use a synchronous ajax request, in which case execution would pause at line 13 until the response comes back, but that provides a poor experience for the user because the browser will be unresponsive in the mean time.

    Better to restructure to stick with standard aysnc Ajax, and allow for the order of execution I described above. Without knowing how your mynamespace.html() is called I’m not sure I can advise on that.

    I believe you’ve run aground on the “Same Origin Policy”, also sometimes called the “Cross-Domain Security Policy” or other variations on that theme.

    You don’t say what types of URL you are entering, but in a general sense JavaScript running in one frame can’t access the content of another frame if the source is from a different domain.

    (There are some workarounds to get cross-domain frames to communicate with each other, but only if both are cooperating – which wouldn’t be the case here.)

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

Sidebar

Related Questions

My function below, will take the values from my custom meta fields (after a
My function below calls a partial view after a user enters a filter-by string
I have the following function below: public function setupHead($title){ $displayHead .='<!DOCTYPE html PUBLIC -//W3C//DTD
I have created the function below which is intended to list the sub categories
The function below prints a color raster image to a PCL-5 printer. The function
The function below is logging the 0, z and the 1 ok... but its
The function below takes a python file handle, reads in packed binary data from
I am using the function below inside a thread to receive the byte[] via
I am using the function below to open the user's default web browser. Public
I have written a function below: void trans(double x,double y,double theta,double m,double n) {

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.