2015-02-02 10 views
18

मुझे G + Follow बटन की क्लिक घटनाओं को कैप्चर करने का प्रयास करते समय समस्या का सामना करना पड़ रहा है।अनचाहे सुरक्षा त्रुटि: 'HTMLFrameElement' से 'contentDocument' प्रॉपर्टी को पढ़ने में विफल: मूल के साथ एक फ्रेम अवरुद्ध "https: // localhost"

Uncaught SecurityError: 'HTMLIFrameElement' से 'contentDocument' संपत्ति को पढ़ने में विफल: मूल के साथ "https://localhost" एक फ्रेम अवरोधित मूल के साथ "https://apis.google.com" एक फ्रेम तक पहुँचने से। प्रोटोकॉल, डोमेन, और बंदरगाहों से मेल खाना चाहिए।

+0

संभावित शिकार [Uncaught SecurityError: से 'HTMLIFrameElement' 'contentDocument' संपत्ति को पढ़ने में विफल] (http://stackoverflow.com/questions/ 26329519) या [सुरक्षा त्रुटि: 'HTMLFrameElement] से' contentDocument 'प्रॉपर्टी को पढ़ने में विफल (http://stackoverflow.com/questions/26657687) – hippietrail

उत्तर

5

मुझे एक समान चर्चा मिली, Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFram

This issue fired when you try to call ajax to another domain, please check this article for more info about Same origin policy

Mozilla's Same Origin article

For fix this, you will need to add this code

document.domain = 'yourdomain.com' 

लेख खुद से:

A page may change its own origin with some limitations. A script can set the value of document.domain to a subset of the current domain. If it does so, the shorter domain is used for subsequent origin checks. For example, assume a script in the document at http://store.company.com/dir/other.html executes the following statement:

document.domain = "company.com"; 

After that statement executes, the page would pass the origin check with http://company.com/dir/page.html . However, by the same reasoning, company.com could not set document.domain to othercompany.com.

The port number is kept separately by the browser. Any call to the setter, including document.domain = document.domain causes the port number to be overwritten with null. Therefore one cannot make company.com:8080 talk to company.com by only setting document.domain = "company.com" in the first. It has to be set in both so that port numbers are both null.

+17

मैंने आपके समाधान की कोशिश की, लेकिन मुझे संदेश मिला: सुरक्षा त्रुटि:' 'दस्तावेज़' पर डोमेन 'संपत्ति': 'http://mimouni.info' i 'लोकलहोस्ट' का प्रत्यय नहीं है। – Mimouni

0

मेरे समाधान ifra reconstructs मुझे और कोणीय में प्रयोग योग्य। जब हम एक आईफ्रेम बनाते हैं, तो इसे आईफ्रेम सामग्री को संशोधित करने के लिए मूल सुरक्षा जांच की आवश्यकता होती है। यह समाधान हमें कई बार आईफ्रेम सामग्री को फिर से बनाने की अनुमति देता है।

एचटीएमएल

<div id="iframecontainer"></div> 

जे एस

var content = "<h1>Content inside Iframe</h1>"; //desired content of iframe 
var iframecontainer = document.getElementById("iframecontainer"); 
iframecontainer.innerHTML ='<iframe id="threedsframe" width="%90" height="400px"></iframe>'; 
var iframe = iframecontainer.childNodes[0]; 
let doc = iframe.contentDocument || iframe.contentWindow; 
doc.open(); 
doc.write(content); 
doc.close(); 
की
संबंधित मुद्दे

 संबंधित मुद्दे