Skip to content

Instantly share code, notes, and snippets.

@kevinvalk
Last active May 12, 2022 10:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinvalk/ae09e21a522c378b2ceb419cf09a36a7 to your computer and use it in GitHub Desktop.
Save kevinvalk/ae09e21a522c378b2ceb419cf09a36a7 to your computer and use it in GitHub Desktop.
Can be used to integrate JIRA issue collector as a iframe form in a page where javascript is not allowed. Call like https://cdn.rawgit.com/kevinvalk/ae09e21a522c378b2ceb419cf09a36a7/raw/a57cb1cb788fa6c141893dd1fdcf185d541c22af/issue_collector.html?url=<JIRA URL>#<ISSUE COLLECTOR ID>.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<script type="text/javascript">
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
function onLoad() {
var iframe = document.getElementById('atlwdg-frame');
var url = "https://" + encodeURIComponent(getUrlParameter('url'));
iframe.onload = function() {
this.contentWindow.postMessage(JSON.stringify({messageType: 'collector.iframe.loaded'}), url);
}
var id = window.location.hash.substr(1);
iframe.src = url + "/rest/collectors/1.0/template/form/" + (id == '' ? '_' : encodeURIComponent(id)) + "?os_authType=none";
}
window.addEventListener("message", function(event) {
switch(event.data) {
case "cancelFeedbackDialog":
alert("Your request has successfully been submitted to JIRA, thanks!");
onLoad(); // Restart collector
break;
};
}, false);
</script>
<style>
html {
height: 100%;
}
body {
height: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
}
#atlwdg-frame {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
}
</style>
</head>
<body onload="onLoad()"><iframe id="atlwdg-frame" scrolling="no" frameborder="0" src=""></iframe></body>
</html>
@vahem2lu
Copy link

Hi
Thanks for useful example!

Do you happen to have encountered this kind of error in Chrome/Safari

"SyntaxError: Unexpected token X in JSON at position 0
    at JSON.parse (<anonymous>)
    at E.parseJSON (https://myjira.jira.domain/s/collector-resource-SANTIIZED-CDN/s50hbe/820008/SANITIZED/SANITIZED/_/download/contextbatch/js/_super/batch.js?locale=et-EE:74:24782)
    at u.parseJSON (https://myjira.jira.domain/s/collector-resource-SANTIIZED-CDN/s50hbe/820008/SANITIZED/SANITIZED/_/download/contextbatch/js/_super/batch.js?locale=et-EE:295:3752)
    at y (https://myjira.jira.domain/s/collector-resource-SANTIIZED-CDN/s50hbe/820008/SANITIZED/SANITIZED/_/download/contextbatch/js/_super/batch.js?locale=et-EE:670:4618)
    at HTMLIFrameElement.n (https://myjira.jira.domain/s/collector-resource-SANTIIZED-CDN/s50hbe/820008/SANITIZED/SANITIZED/_/download/contextbatch/js/_super/batch.js?locale=et-EE:670:2258)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment