애플리케이션 성늘관리 조건과 전략

memo 세미나 2014.07.25 08:19

Trackback 0 : Comment 0

iframe javascript access parent cross domain

script 2014.07.14 19:23


[출처] http://stackoverflow.com/questions/1291812/iframe-javascript-access-parent-dom-across-domains


 -parent page-


<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>

    <!--
    <link rel="shortcut icon" href="/favicon.ico">


    <link rel="start" href="http://benalman.com/" title="Home">

    <link rel="stylesheet" type="text/css" href="/code/php/multi_file.php?m=benalman_css">

    <script type="text/javascript" src="/js/mt.js"></script>
    -->
    <script type="text/javascript">
        // What browsers support the window.postMessage call now?
        // IE8 does not allow postMessage across windows/tabs
        // FF3+, IE8+, Chrome, Safari(5?), Opera10+

        function SendMessage()
        {
            var win = document.getElementById("ifrmChild").contentWindow;

            // http://robertnyman.com/2010/03/18/postmessage-in-html5-to-send-messages-between-windows-and-iframes/


            // http://stackoverflow.com/questions/16072902/dom-exception-12-for-window-postmessage
            // Specify origin. Should be a domain or a wildcard "*"

            if (win == null || !window['postMessage'])
                alert("oh crap");
            else
                win.postMessage("hello", "*");
            //alert("lol");
        }



        function ReceiveMessage(evt) {
            var message;
            //if (evt.origin !== "http://robertnyman.com")
            if (false) {
                message = 'You ("' + evt.origin + '") are not worthy';
            }
            else {
                message = 'I got "' + evt.data + '" from "' + evt.origin + '"';
            }

            var ta = document.getElementById("taRecvMessage");
            if (ta == null)
                alert(message);
            else
                document.getElementById("taRecvMessage").innerHTML = message;

            //evt.source.postMessage("thanks, got it ;)", event.origin);
        } // End Function ReceiveMessage




        if (!window['postMessage'])
            alert("oh crap");
        else {
            if (window.addEventListener) {
                //alert("standards-compliant");
                // For standards-compliant web browsers (ie9+)
                window.addEventListener("message", ReceiveMessage, false);
            }
            else {
                //alert("not standards-compliant (ie8)");
                window.attachEvent("onmessage", ReceiveMessage);
            }
        }
    </script>


</head>
<body>

    <iframe id="ifrmChild" src="child.htm" frameborder="0" width="500" height="200" ></iframe>
    <br />


    <input type="button" value="Test" onclick="SendMessage();" />

</body>
</html>


 -child page-


<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>

    <!--
    <link rel="shortcut icon" href="/favicon.ico">


    <link rel="start" href="http://benalman.com/" title="Home">

    <link rel="stylesheet" type="text/css" href="/code/php/multi_file.php?m=benalman_css">

    <script type="text/javascript" src="/js/mt.js"></script>
    -->

    <script type="text/javascript">
        /*
        // Opera 9 supports document.postMessage() 
        // document is wrong
        window.addEventListener("message", function (e) {
            //document.getElementById("test").textContent = ;
            alert(
                e.domain + " said: " + e.data
                );
        }, false);
        */

        // https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage
        // http://ejohn.org/blog/cross-window-messaging/
        // http://benalman.com/projects/jquery-postmessage-plugin/
        // http://benalman.com/code/projects/jquery-postmessage/docs/files/jquery-ba-postmessage-js.html

        // .data – A string holding the message passed from the other window.
        // .domain (origin?) – The domain name of the window that sent the message.
        // .uri – The full URI for the window that sent the message.
        // .source – A reference to the window object of the window that sent the message.
        function ReceiveMessage(evt) {
            var message;
            //if (evt.origin !== "http://robertnyman.com")
            if(false)
            {
                message = 'You ("' + evt.origin + '") are not worthy';
            }
            else
            {
                message = 'I got "' + evt.data + '" from "' + evt.origin + '"';
            }

            //alert(evt.source.location.href)

            var ta = document.getElementById("taRecvMessage");
            if(ta == null)
                alert(message);
            else
                document.getElementById("taRecvMessage").innerHTML = message;

            // http://javascript.info/tutorial/cross-window-messaging-with-postmessage
            //evt.source.postMessage("thanks, got it", evt.origin);
            evt.source.postMessage("thanks, got it", "*");
        } // End Function ReceiveMessage




        if (!window['postMessage'])
            alert("oh crap");
        else {
            if (window.addEventListener) {
                //alert("standards-compliant");
                // For standards-compliant web browsers (ie9+)
                window.addEventListener("message", ReceiveMessage, false);
            }
            else {
                //alert("not standards-compliant (ie8)");
                window.attachEvent("onmessage", ReceiveMessage);
            }
        }
    </script>


</head>
<body style="background-color: gray;">
    <h1>Test</h1>

    <textarea id="taRecvMessage" rows="20" cols="20" ></textarea>

</body>
</html>





'script' 카테고리의 다른 글

JQuery 와 Prototype 충돌  (0) 2016.05.26
InvalidCharactErerror  (0) 2016.01.11
iframe javascript access parent cross domain  (0) 2014.07.14
swap memory used check in sh  (0) 2014.07.03
JAVACRIPT 와 PHP 간 암호화 복호화 연동  (0) 2014.06.27
화면회전 in javascript  (0) 2014.04.15
Trackback 0 : Comment 0

swap memory used check in sh

script 2014.07.03 16:26

[출처] https://github.com/sensu/sensu-community-plugins/blob/master/plugins/system/check-swap.sh


#!/bin/bash
#
# Evaluate swap memory usage from Linux based systems.
#
# Date: 2007-11-12
# Author: Thomas Borger - ESG
# Date: 2012-04-02
# Modified: Norman Harman - norman.harman@mutualmobile.com
# Date: 2013-03-13
# Modified: Jean-Francois Theroux - jtheroux@lapresse.ca
#
# The swap check is done with following command line:
# vmstat | tail -n1 | awk '{ print $3 }'
 
# get arguments
 
while getopts 'w:c:hp' OPT; do
  case $OPT in
    w) WARN=$OPTARG;;
    c) CRIT=$OPTARG;;
    h) hlp="yes";;
    p) perform="yes";;
    *) unknown="yes";;
  esac
done
 
# usage
HELP="
usage: $0 [ -w value -c value -p -h ]
-w --> Warning MB < value
-c --> Critical MB < value
-p --> print out performance data
-h --> print this help screen
"
 
if [ "$hlp" = "yes" ]; then
  echo "$HELP"
  exit 0
fi
 
WARN=${WARN:=0}
CRIT=${CRIT:=0}
 
USED_SWAP=$((`vmstat | tail -n1 | awk '{ print $3 }'` / 1024 ))
 
if [ "$USED_SWAP" = "" ]; then
  echo "SWAP UNKNOWN -"
  exit 3
fi
 
if [ "$perform" = "yes" ]; then
  output="used swap memory: $USED_SWAP MB | used swap memory="$USED_SWAP"MB;$WARN;$CRIT;0"
else
  output="used swap memory: $USED_SWAP MB"
fi
 
if (( $USED_SWAP >= $CRIT )); then
  echo "SWAP CRITICAL - $output"
  exit 2
elif (( $USED_SWAP >= $WARN )); then
  echo "SWAP WARNING - $output"
  exit 1
else
  echo "SWAP OK - $output"
  exit 0
fi


Trackback 0 : Comment 0