postmessage

php跨域的几种方式

允我心安 提交于 2019-12-03 10:54:23
PHP实现跨域的几种形式 1、JSONP(JSON with padding)原理 利用html里面script标签可以加载其他域下的js这一特性,使用script src的形式来获取其他域下的数据,但是,因为是通过标签引入的,所以,会将请求到的JSON格式的数据作为js去运行处理,显然这样运行是不行的。 因此,就需要提前将返回的数据包装一下,封装成函数进行运行处理,函数名通过接口传参的方式传给后台,后台解析到函数名后在原始数据上包裹这个函数名,发送给前端。(JSONP 需要对应接口的后端的配合才能实现) 实例: 当script src请求到达后端后,后端会去解析callback这个参数,获取到字符串showData,在发送数据后端返回数据,用showData封装一下,即showData({"json数据"}) ,前端script标签在加载数据后,会把json数据作为showData的参数,调用函数运行。 2、CORS CORS全称是跨域资源共享(Cross-Origin Resource Sharing),是一种 ajax 跨域请求资源的方式,支持现代浏览器,IE支持10以上。 实现方式: 当使用XMLHttpRequest发送请求时,浏览器发现该请求不符合同源策略,会给该请求加一个请求头:Origin,后台进行一系列处理,如果确定接受请求,则在返回结果中加入一个响应头

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin 'my_page' in a call to 'postMessage'

别来无恙 提交于 2019-12-03 10:20:46
i have following script Parent Page(pair_pixel_filter.php): window.addEventListener("message", function(e) { $('#log').append("Received message: " + (e.data)); }, false); $('.photo-upload-btn').click(function(event) { event.preventDefault(); window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes"); }); The Child Page $.ajax({ type: 'post', url: url, data: { base64data: dataURL }, success: function(data) { window.opener.postMessage(data, "pair_pixel_filter.php"); window.close(); } }); Basically opening a Popup and then doing some ajax on pop up and returning

Using PostMessage/SendMessage to send keys to c# IE WebBrowser

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to auto fill in values in the C# webbrowser control and tab and enter and press up and down to move through the fields. Here is my PInvoke and wrapper functions. I used Spy++ to get these in Internet Explorer. Does anyone see anything wrong with my definitions? I want to use Send and Post message instead of SendInput because I don't want to have to focus the window... [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); [DllImport(

postMessage() generates error “undefined is not a function”

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to get postMessage() to work to communicate between an iframe and my main website. However using the exact syntax given in the example code on MDN , I am being presented with a nice Undefined is not a function error. I've tried several things, such as initializing the iframe inside Javascript and appending it to my page, but that left me with the same error. Same for have seperate selectors to select my iframe. I have the following Javascript code: <script type="text/javascript"> $(document).ready(function() { $('.editor')

实现跨域的5种方法

二次信任 提交于 2019-12-03 08:06:57
1、jsonp 最常见的一种跨域方式,其背后原理就是利用了script标签不受同源策略的限制,在页面中动态插入了script,script标签的src属性就是后端api接口的地址,并且以get的方式将前端回调处理函数名称告诉后端,后端在响应请求时会将回调返还,并且将数据以参数的形式传递回去。 前端: //http://127.0.0.1:8888/jsonp.html var script = document.createElement('script'); script.src = 'http://127.0.0.1:2333/jsonpHandler?callback=_callback' document.body.appendChild(script); //插入script标签 //回调处理函数 _callback var _callback = function(obj){ for(key in obj){ console.log('key: ' + key +' value: ' + obj[key]); } } 后端: //http://127.0.0.1:2333/jsonpHandler app.get('/jsonpHandler', (req,res) => { let callback = req.query.callback; let obj = {

communication between browser tab

南笙酒味 提交于 2019-12-03 07:34:34
i've an html page (main.html) opening a new tab in the same domain using javascript with window.open("newtab.html") method. In the new tab users do something ending his activity clicking a button. At this point I would like to send a message to the opener window. I tried with postMessage but from new tab I can't have a reference to the opener. From new tab I'd like something like but I've "ko" var w = window.opener; if (w) { w.postMessage("hi", "http://10.150.10.43"); } else { alert("ko"); } What is the best way to send message from the secondary tab/window to the main one (in the same domain)

javascript - postMessage to sandboxed iframe, why is recipient window origin null?

末鹿安然 提交于 2019-12-03 05:44:13
2 postMessage calls in the test: 1 using an asterisk for targetOrigin, one using the same https url of both the parent and child documents. button 1: $('.iframed')[0].contentWindow.postMessage( messageData , '*' ); button 2: $('.iframed')[0].contentWindow.postMessage( messageData , 'https://myurl.net' ); the iframe element in parent html document, which points to child html file on same domain, in same directory: <iframe name="childFrame" class="iframed" src="child.html" sandbox="allow-scripts"></iframe> both documents are fully loaded before I am clicking the buttons to trigger postMessage. =

jQuery doesn't support postmessage event?

余生长醉 提交于 2019-12-03 05:25:50
问题 When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e) { var data = e.data; // data = undefined }); data is undefined! I'm sure that I have passed data to current window. Because if I use "addEventListener", everything goes well! So, what's the problem? 回答1: jQuery might be preprocessing the event's data property, and this operation may not properly support the message event (yet). Try using the originalEvent property to fetch your data: $

User32 API custom PostMessage for automatisation

被刻印的时光 ゝ 提交于 2019-12-03 04:00:52
I want to automate a program called Spotify from C#, the best way (I think) to do this is by triggering fake keypresses. I want to program to pause playback, and I don't know enough about this stuff to find another way than keypresses. So I use Visual Studio's Spy++ to see what message Spotify gets when pressing the play button on my keyboard, I copy the data from that message into my Console Application and run it, when I run I can see the PostMessage in Spy++'s Message Logging, so this is working but it doesn't pause/play my music. I guess this is because I also have to send another

Uncaught SyntaxError: Failed to execute &#039;postMessage&#039; on &#039;Window&#039;: Invalid target origin &#039;my_page&#039; in a call to &#039;postMessage&#039;

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i have following script Parent Page(pair_pixel_filter.php): window.addEventListener("message", function(e) { $('#log').append("Received message: " + (e.data)); }, false); $('.photo-upload-btn').click(function(event) { event.preventDefault(); window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes"); }); The Child Page $.ajax({ type: 'post', url: url, data: { base64data: dataURL }, success: function(data) { window.opener.postMessage(data, "pair_pixel_filter.php"); window.close(); } }); Basically opening a Popup