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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:56:04+00:00 2026-05-14T05:56:04+00:00

I working on adding file uploading to my web application. I’m using an iframe

  • 0

I working on adding file uploading to my web application. I’m using an iframe to post my upload. When my php script processes the upload it writes some JavaScript to the iframe. This JavaScript is attempting to attach a function to the parent, this works, but when this function actually gets called it doesn’t have the correct scope. Here is the code I’m attaching to the parent window:

parent.window.showPreview = function(coords)
{
    if (parseInt(coords.w) > 0)
    {
        var rx = 200 / coords.w;
        var ry = 250 / coords.h;

        $('#preview').css({
            width: Math.round(rx * 400) + 'px',
            height: Math.round(ry * 533) + 'px',
            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
            marginTop: '-' + Math.round(ry * coords.y) + 'px'
        });
    }
}

When this function gets executed I get an error that says $ is not defined. I’ve tried adding changing the JQuery call to parent.$(‘#preview’).css…, but then it says that parent is undefined. Any ideas?

  • 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-14T05:56:04+00:00Added an answer on May 14, 2026 at 5:56 am

    Try this:

    var p$ = parent.window.$;
    parent.window.showPreview = function(coords) {
        if (parseInt(coords.w) > 0)
        {
            var rx = 200 / coords.w;
            var ry = 250 / coords.h;
    
            p$('#preview').css({
                width: Math.round(rx * 400) + 'px',
                height: Math.round(ry * 533) + 'px',
                marginLeft: '-' + Math.round(rx * coords.x) + 'px',
                marginTop: '-' + Math.round(ry * coords.y) + 'px'
            });
        }
    }
    

    If you’re making a function for the parent window, you probably want it to use the parent window’s jQuery instead of the child window’s. You’ll also need to make sure the parent page has its own copy of jQuery. (If it doesn’t, and you’re brave, you could try dynamically giving it one!)

    edit

    Here’s how you could do it with a closure instead of the global p$:

    parent.window.showPreview = (function(p$) {
      return function(coords) {
        // ... same as above
      };
    })(parent.window.$);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • 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 The idea from my answer to your previous question was… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer If it works in Landscape, it should also work in… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer Each time an element is focused, you'd have to store… May 16, 2026 at 4:00 pm

Trending Tags

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

Top Members

Related Questions

I'm looking for a way to upload a file to s3. I am using
I am uploading files using SWFUpload. To get the data I need passed along
I am working on adding some nagios alerts to our system -- some of
I'm working on adding a feature to an old classic asp site and ran
I've having trouble adding a rtf file to license agreement installation window, does anyone
So my background is in Java web services, but I'm trying to make the
I have an Send.aspx page that has an uploadify control on it. Upload.ashx handles
I am working on a chat implementation with Java sockets. I have focused on
First, the background: I'm working in Tapestry 4, so the HTML for any given
I am working on a login section for a new project, which definitely requires

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.