'Program button to open new page if clicked when in iframe, but same page if clicked outside of iframe
I am creating a simple 'in-browser' python IDE (here: coder.computerscienceuk.com/coder) and have a save button which saves the editor code to a new URL.
How can I program the save button so that when visiting the main website it opens the new URL on the same page (as it currently does) but if the button is clicked from within an iFrame (embedded on another site) it forces the new URL to open in a new window/tab?
Here is my button code:
function remix(private) {
var private = private;
var codedata = myCodeMirror.getValue();
var uid = $js_userID;
var ide = $js_ide;
var response;
if (private == 1 && uid == 0) {
alert("You need to be logged in to save to a private URL");
} else {
$.ajax({
type: "POST",
url: {$js_url} + '/wp-content/plugins/CSUKCODER/remix.php',
data: {"codedata" : codedata, "uid" : uid, "ide" : ide, "private" : private},
success: function(data) {
response = data;
response = response.replace('"','');
response = parseInt(response);
hashids = new Hashids();
id = hashids.encode(response);
window.open($js_urlpage + String(id), '_self')
},
error: function (request, status, error) {
alert(request.responseText);
}
});
};
}
<img src="$pluginRootPath/img/diskette.png" style="height:45px; padding-left:10px; cursor:pointer;" onclick="remix(0)" title="Save to URL">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
