call js outsite iframe

  • How i can call JS in construct and run this function out iframe?

    i have code:

    <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>
    [/code:2lyg8tlx]
    
    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...
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Please help me

  • If you have a page embeded in an iFrame and want to call it from parent, here's how:

    [event] | Browser.ExecuteJavascript 
    "var iframe = document.getElementById(""myframe"");
    if (iframe) {
       var iframeContent = (iframe.contentWindow || iframe.contentDocument);
         var doc = iframe.contentWindow.document;
    
    // Your code here
    
    }"[/code:1a2x6fsr]
    
    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".
  • ok Tanks:) so i can put my code there?

    This code?:

    <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>[/code:s8m2h35t]
    and this run my javascript out iframe ?
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)