0

what i am trying to do is to get the value from a textbox and load it into a container like so:

var script = $('#txtbox').val();
$('.container').html(script);

i also tried creating the script again with javascript by finding the values of the one the user inserted and creating a new one and appending it into the container as so:

var tempdiv = $("<div></div>").html($('#txtbox').val());
$(tempdiv).find('script').each(function(index,$element){
     var script = document.createElement("script");
    $.each($element.attributes, function(){
        if (this.specified){
            script.setAttribute(this.name, this.value);
        }
    });
    script.innerHTML = $($element).html();
    $('.container').append(script); 
});

but still doesn't work, i get:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script

Any suggestions? maybe try loading the script in iframe, refresh the DOM somehow or what?

Rory McCrossan
  • 306,214
  • 37
  • 269
  • 303
sstauross
  • 2,056
  • 1
  • 24
  • 48

1 Answers1

0

I solved that by using an iframe. In javascript i just created a form and a hidden input field which are submitted to the page that the iframe loads.

Check JavaScript post request like a form submit for more details.

Community
  • 1
  • 1
sstauross
  • 2,056
  • 1
  • 24
  • 48