能否获取无原文弹窗的必应翻译小部件?已尝试指定代码无效
Hey there! I’ve run into similar hiccups with the Bing Translator Widget before—those original text popups can be super intrusive when you don’t want them. The reason your code didn’t take effect is almost certainly because you ran it before the widget finished loading—the domTranslator object simply didn’t exist yet when your script executed.
Here’s a reliable fix to get those settings working:
Step 1: Wrap your settings in an initialization function
First, create a function that applies your desired preferences once the widget is fully ready:
function configureTranslatorWidget() { // Turn off highlight effects and original text tooltips Microsoft.Translator.Widget.domTranslator.showHighlight = false; Microsoft.Translator.Widget.domTranslator.showTooltips = false; // Force the widget to apply the new settings right away Microsoft.Translator.Widget.domTranslator.refresh(); }
Step 2: Trigger the function when the widget loads
When embedding the widget script, use the data-oncomplete attribute to run your configuration function immediately after the widget finishes initializing:
<script type="text/javascript" src="https://www.bing.com/translator/api/WidgetV3/Widget.js" data-type="script" data-oncomplete="configureTranslatorWidget"> </script>
Why this works
The data-oncomplete attribute ensures your code only runs once the widget’s internal objects (like domTranslator) are fully set up. Without this timing check, your original code would try to modify properties that don’t exist yet, leading to no visible changes.
If you’re still stuck, double-check that no other scripts on your page are overriding these settings, and confirm you’re using the latest version of the Bing Translator Widget.
Give this a shot—I’m confident it’ll get rid of those unwanted popups!
内容的提问来源于stack exchange,提问作者Chaitu

