< >

post-message.php


Quell Code


<iframe src="loesungen/index.php?ordner=loesungen&mame=beispiel-iframe.html"  id="iframe"></iframe>
<form id="form">
  <input type="text" id="msg" value="Message to send"/>
  <input type="submit"/>
</form>
<script>
window.onload = function(){
    var win = document.getElementById("iframe").contentWindow;
	document.getElementById("form").onsubmit = function(e){
		win.postMessage(
			document.getElementById("msg").value,
			"https://sebastian1012.bplaced.net/"
		);
		e.preventDefault();
	};
};
</script>


<iframe src="loesungen/index.php?ordner=loesungen&mame=beispiel-iframe.html" id="rame"></iframe>

<script>
var domain = 'https://sebastian1012.bplaced.net/';
var iframe = document.getElementById('rame').contentWindow;



	window.addEvent('domready',function() {
		//create popup window
		var domain = 'https://sebastian1012.bplaced.net';
		var iframe = document.getElementById('listenerFrame').contentWindow;
		
		//periodical message sender
		var times = 0;
		var inty = setInterval(function(){
			var message = 'Hello!  The time is: ' + (new Date().getTime());
			console.log('davidwalsh.name:  sending message:  ' + message);
			iframe.postMessage(message,domain);
			if(++times == 3) { clearInterval(inty); }
		},2000);
		
		/* click - control event */
		Element.NativeEvents.message = 2;
		Element.Events.message = {
			base: 'message',
			condition: function(event) {
				//if(event.type == 'message') {
				if(!event.$message_extended) {
					event.$message_extended = true;
					event.data = event.event.data;
					event.source = event.event.source;
					event.origin = event.event.origin;
					for(key in event) {
						if(event[key] == undefined) {
							event[key] = false;
						}
					}
				}
				return true;
			}
		};
		
		//listen to holla back
		//window.addEventListener('message',function(event) {
		window.addEvent('message',function(event) {
			console.log('received pingback from scriptandstyle.com: ',event,event.event);
			if(event.event.origin !== 'https://davidwalsh.name') return;
			console.log('davidwalsh.name:  received reponse:  ',event.event.data);
		});

	});
	</script>