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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:57:29+00:00 2026-06-08T12:57:29+00:00

I trying to create iframe then add script to it and script will run.

  • 0

I trying to create iframe then add script to it and script will run. Iframe created, but it always get errors in process of appending script to that iframe. Please help.

<div align="center" id="adframe1">
<script type="text/javascript">
var response1 = '<script>var ad_unit="123";</scr'+'ipt><script src="http://abc.com/abc.js"></scr'+'ipt>';
$('<iframe id="adframe1mopub"/>').appendTo('#adframe1');
$('#adframe1mopub').ready(function() {
$('#adframe1mopub').contents().find('body').append(response1);
});
</script>
</div>
  • 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-08T12:57:31+00:00Added an answer on June 8, 2026 at 12:57 pm

    You can try this script:

    HTML:

    ​<div id=container-iframe>​</div>​​​​​​​
    

    JS:

    var response1 = '<script>var ad_unit="123";</scr' + 'ipt><script src="http://abc.com/abc.js"></scr' + 'ipt>';
    
    $('<iframe></iframe>', { id: 'adframe1mopub' }).bind('load', function(event) {
    
        if (!this.contentWindow) {
            return;
        }
    
        this.contentWindow.document.body.innerHTML += response1;
    
    }).appendTo('#container-iframe');
    

    But it would be best way to implement this:

    $('<iframe></iframe>', { id: 'myiframe' }).bind('load', function(event) {
    
        if (!this.contentWindow) {
            return;
        }
    
        var scripWidthCode = document.createElement('script');
        scripWidthCode.type ='text/javascript';
        scripWidthCode.innerText = 'var ad_unit="123";';
    
        this.contentWindow.document.getElementsByTagName('head')[0].appendChild(scripWidthCode);
    
        var scripWidthSrc = document.createElement('script');
        scripWidthSrc.type ='text/javascript';
        scripWidthSrc.src = 'http://abc.com/abc.js';
    
        this.contentWindow.document.getElementsByTagName('head')[0].appendChild(scripWidthSrc);
    
    }).appendTo('#container-iframe');
    

    ​
    test

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

Sidebar

Related Questions

Trying to create a new Dedicated Cache Role in Windows Azure but get the
I'm trying to create file upload using iframe(ajax effect) but I need to know
I'm trying to add an iframe using jquery this way below, but when I
Ok so I am trying create a login script, here I am using PHP5
Trying to create a black line in my view to separate text blocks but
I'm trying to create a widget (which is basically an iframe) that would have
I'm trying to create a method that will send a PDF file directly to
I'm trying to get a page to show a loading... message while I create
I am trying to create an iframe with a height of 100% and a
I'm trying to create an iFrame application with some static content and a comment

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.