簡體   English   中英

Javascript google 音譯 API 不通過 h​​ttps 提供

[英]Javascript google transliterate API not served over https

JavaScript google 音譯 API 不通過 h​​ttps 提供服務。 我低於混合內容錯誤。 它在 http 網站上工作,但不適用於 https。 我嘗試通過以下所有方式調用 API。

 <script type="text/javascript" src="https://google.com/jsapi">
 <script type="text/javascript" src="http://google.com/jsapi">
 <script type="text/javascript" src="//google.com/jsapi">
 <script type="text/javascript" src="//www.google.com/jsapi">

錯誤:

混合內容:“ https://extranuclear-freque.000webhostapp.com/lang.html ”上的頁面已通過 HTTPS 加載,但請求了不安全的腳本“ http://www.google.com/inputtools/request?text=” gy&ime=transliteration_en_bn&num=5&cp=0&cs=0&ie=utf-8&oe=utf-8&app=jsapi&uv&cb=回調._2j46jfkrs '。 此請求已被阻止; 內容必須通過 HTTPS 提供。

請幫幫我。 謝謝

 <pre> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="https://www.google.com/jsapi"> </script> <script type="text/javascript"> google.load("elements", "1", { packages: "transliteration" }); function onLoad() { var options = { sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH, destinationLanguage: [google.elements.transliteration.LanguageCode.BENGALI], shortcutKey: 'ctrl+g', transliterationEnabled: true }; var control = new google.elements.transliteration.TransliterationControl(options); control.makeTransliteratable(['transliterateTextarea']); } google.setOnLoadCallback(onLoad); </script> </head> <body> <textarea id="transliterateTextarea" style="width:600px;height:200px"></textarea> </body> </html> </pre>

我找到了一種解決上述錯誤的解決方案,您只需在上傳服務器時將此行粘貼到 Meta 標記下方即可..如果您覺得這有幫助,請告訴我..

 <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

將此( https://www.google.com/uds/api/elements/1.0/7ded0ef8ee68924d96a6f6b19df266a8/transliteration.I.js )文件保存在本地

找到 "qi="http://www.google.com" 然后將其更改為 qi="https://www.google.com"

它會工作

這是對@Nitin Goyal 上一個回答的描述

我對這個問題進行了研究,發現谷歌在translationI.js 中有硬核

要解決此問題,您可以將該文件下載到您的計算機並上傳到您自己的服務器並將http://google.com更改為https://google.com以解決您的問題

下面是一個分步過程:


首先,有一個指向 API 的鏈接:

<script type="text/javascript" src="https://www.google.com/jsapi">

其次,訪問上面的API鏈接並搜索如下內容:

google.loader.ServiceBase = 'https://www.google.com/uds';

現在,這是重要的部分!

您需要替換google.loader.ServiceBase = 'yourfile.js';的鏈接

注意: yourfile.js是您創建的腳本。

要做到這一點 - 您需要創建兩個單獨的 JavaScript 文件。 為什么? 因為 google.loader.ServiceBase 在 google.com/jsapi 里面

這是我做的過程:

第 1 步:創建兩個 JavaScript 文件 - 比如說main.jsextra.js

第二步:https://www.google.com/jsapi的內容保存到main.js

第三步:https://www.google.com/uds/api/elements/1.0/7ded0ef8ee68924d96a6f6b19df266a8/transliteration.I.js的內容保存到extra.js

第4步:extra.js中-找到qi="http://www.google.com"並替換為qi="https://www.google.com" -記住http改為https並保存。

第 5 步:現在回到main.js - 你必須找到the google.loader.ServiceBase = 'https://www.google.com/uds'; 並替換為google.loader.ServiceBase = 'extra.js'; 並保存它。

第 6 步:調用 javascript - main.js之一到您的 html。

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

為所有面臨彈出窗口未正確顯示問題的人擴展 Min Somai 的回答。

  1. 從此鏈接復制 CSS 並將其添加到文件transliteration.css 中 將以下行添加到 index.html
<link type="text/css" href="assets/google/js/transliteration.css" rel="stylesheet"/>
  1. 這應該為您提供顯示音譯彈出窗口所需的正確 CSS。
  var control =
            new google.elements.transliteration.TransliterationControl(options);

        var ids = ["transl1", "transl2"];
        control.makeTransliteratable(ids);


//Add the following line to make it work over https

control.c.qc.t13n.c[3].c.d.keyup[0].ia.F.p = 'https://www.google.com';

工作演示:

 <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("elements", "1", { packages: "transliteration" }); function onLoad() { var options = { sourceLanguage: [google.elements.transliteration.LanguageCode.ENGLISH], destinationLanguage: [google.elements.transliteration.LanguageCode.HINDI ], shortcutKey: 'ctrl+g', transliterationEnabled: true }; var control = new google.elements.transliteration.TransliterationControl(options); // Enable transliteration in the textbox with id 'transliterateTextarea'. control.makeTransliteratable(['transliterateTextarea']); //Add the following line to make it work over https control.c.qc.t13n.c[3].cdkeyup[0].ia.Fp = 'https://www.google.com'; } google.setOnLoadCallback(onLoad); </script> </head> <body> <textarea id="transliterateTextarea" style="width:600px;height:200px">यहाँ टाइप करे ...</textarea> <p>(Press Ctrl+g to toggle between English and Hindi)</p> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM