1

I am rendering an Iframe within a greasemonkey script, which renders a webpage from my back-end webservice. At the minute I can make a GET request and everything works fine but going forward my URL will be enormous if I want to pass more content to my back-end.

Looking at How do you post to an iframe? I am able to create a form which posts information to my back-end, which then parses the post and dumps it within the IFrame.

What I am looking to do is upon page load make a post request with greasemonkey to my webservice and then render the information within the IFrame without any input from the user.

Below is what I have got so far:

$(document).ready(function() {

/*Get Account ID */
var accountID = getAccountId();
var requestUrl = getUrl();
var subject= getSubject();

/* Find the main container */
var mainContainer = document.getElementById('container');
mainContainer.style.width = '78%';
var divContainer = document.createElement('div');
divContainer.id = "div-Decorator"; 


/* Post data  */
var form = document.createElement('form');
form.action = apiUrl;
form.method = "post";
form.target = "resource-Decorator";

var formInput = document.createElement('input');
formInput.type = "text";
formInput.name = "AccountID"
formInput.value = accountID;

var formInput1 = document.createElement('input');
formInput1.type = "text";
formInput1.name = "Topic"
formInput1.value = caseSubject;

var formInputSubmit = document.createElement('input');
formInputSubmit.type = "submit";
formInputSubmit.value = "post";


var iframe = document.createElement('iframe');
iframe.id = "resource-Decorator";
iframe.name = "resource-Decorator";
iframe.src = requestUrl;
iframe.scrolling = "auto";

divContainer.appendChild(form);
form.appendChild(formInput);
form.appendChild(formInput1);
form.appendChild(formInputSubmit);
divContainer.appendChild(iframe);
document.body.appendChild(divContainer);

});
Community
  • 1
  • 1
Ciaran
  • 1,139
  • 2
  • 11
  • 14
  • 1
    Put the form inside the iframe. Have a script instance running in the iframe too (or, since ***you*** are serving the framed page, just have the iframed-page's JS do what's needed). Use `postMessage` to communicate between the original userscript and whatever's running in the iframe. See [here](http://stackoverflow.com/a/11774184/331508) and [here](http://stackoverflow.com/a/11489451/331508). – Brock Adams Apr 25 '14 at 00:02

0 Answers0