GWT Blocked a frame with origin “http://localhost” from accessing a cross-origin frame

梦想与她 提交于 2019-12-24 20:03:00

问题


I would like to allow the user enter their url and browse in the iframe. After they click the confirm button, i will get the url the browse from the iframe.

IFrameElement frame = IFrameElement.as(DOM.createIFrame());
frame.setSrc("http://www.example.com"); //set the url of user enter
VerticalPanel ver = new VerticalPanel();
ver.getElement().appendChild(frame);

// After they click the confirm button, get the url from iframe
Window.alert(frame.getContentDocument().getURL());

But i got an error after i get the url from iframe

Exception: com.google.gwt.event.shared.UmbrellaException: Exception caught: (SecurityError) : Blocked a frame with origin "http://localhost" from accessing a cross-origin frame.


回答1:


In short: you should not do this and you can not do this.


First:

Some pages' authors simply do not want to let their pages to be displayed in a frame. Try Facebook for example, you'll get:

Refused to display 'https://www.facebook.com/' in a frame because it set 'X-Frame-Options' to 'deny'.

One can also check (with a script) if the page is in a frame and 'break through' and take main window, http://www.interia.pl/ is an example.

So, there are pages that can not be shown in a frame.


Second:

Read about Same Origin Policy (SOP):

Simply stated, the SOP states that JavaScript code running on a web page may not interact with any resource not originating from the same web site. The reason this security policy exists is to prevent malicious web coders from creating pages that steal web users’ information or compromise their privacy. While very necessary, this policy also has the side effect of making web developers’ lives difficult.



来源:https://stackoverflow.com/questions/47862088/gwt-blocked-a-frame-with-origin-http-localhost-from-accessing-a-cross-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!