call js outsite iframe

Get help using Construct 3!

Post » Tue Jul 11, 2017 10:43 am

How i can call JS in construct and run this function out iframe?
i have code:
Code: Select all
<body>

<div id="trophy"><img class="img-responsive" src="media/image.png"></div>
<input id="target" type="button" />

<iframe style="border:0px;border-radius:10px" width="100%" height="100%" src="game/index.html">
  <p>MY GAME CANVAS HERE</p>
</iframe>

<script>
// Collection animation
$('#target').click(function () {
    moveChatWindow('righttop');
});

var chatWindow = $('#trophy');
var chatWidth = chatWindow.width();
var chatHeight = chatWindow.height();

var windowWidth = $(window).width();
var windowHeight = $(window).height();

$(window).resize(function () {
    windowWidth = $(window).width();
    windowHeight = $(window).height();
   
    moveChatWindow(chatWindow.data('currentPosition'));
});

function moveChatWindow(moveTo) {
   
    chatWindow.data('currentPosition', moveTo);
     if (moveTo === 'righttop') {
        chatWindow.stop().animate({
             bottom: windowHeight - chatHeight
           , right: 0
        }, 2500);
         $('#trophy').css('opacity', '1');
         $('#trophy').fadeOut(300);
         $('#trophy').css('margin-right', '0');
        $('#trophy').css('margin-bottom', '0');
    }}
</script>
</body>


now i can run this js function frome script when i click on buttom. How i can run this function from event in construct iframe?

If somone help me i can reward:)
sorry for my english lang...
B
10
S
4
G
1
Posts: 29
Reputation: 898

Post » Wed Jul 12, 2017 8:29 am

Please help me
B
10
S
4
G
1
Posts: 29
Reputation: 898

Post » Wed Jul 12, 2017 9:05 am

If you have a page embeded in an iFrame and want to call it from parent, here's how:
Code: Select all
[event] | Browser.ExecuteJavascript
"var iframe = document.getElementById(""myframe"");
if (iframe) {
   var iframeContent = (iframe.contentWindow || iframe.contentDocument);
     var doc = iframe.contentWindow.document;

// Your code here

}"


You place your js code there inside, just as you would normally.

Also make sure your iFrame has an ID – in the upper example, the ID is "myframe".
B
32
S
7
G
4
Posts: 398
Reputation: 4,591

Post » Wed Jul 12, 2017 10:01 am

ok Tanks:) so i can put my code there?
This code?:
Code: Select all
<script>
// Collection animation
$('#target').click(function () {
    moveChatWindow('righttop');
});

var chatWindow = $('#trophy');
var chatWidth = chatWindow.width();
var chatHeight = chatWindow.height();

var windowWidth = $(window).width();
var windowHeight = $(window).height();

$(window).resize(function () {
    windowWidth = $(window).width();
    windowHeight = $(window).height();
   
    moveChatWindow(chatWindow.data('currentPosition'));
});

function moveChatWindow(moveTo) {
   
    chatWindow.data('currentPosition', moveTo);
     if (moveTo === 'righttop') {
        chatWindow.stop().animate({
             bottom: windowHeight - chatHeight
           , right: 0
        }, 2500);
         $('#trophy').css('opacity', '1');
         $('#trophy').fadeOut(300);
         $('#trophy').css('margin-right', '0');
        $('#trophy').css('margin-bottom', '0');
    }}
</script>

and this run my javascript out iframe ?
B
10
S
4
G
1
Posts: 29
Reputation: 898


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 1 guest