NuxtJS automatically adds script at the end of the body - javascript

I'm a newbie NuxtJS programmer. I just searched all over the internet but couldn't find the answer.
I'm just wondering that is it natural that NuxtJS automatically adds the script at the end of the body described as below.
<script type="text/javascript">
document.oncontextmenu = null;
document.onselectstart = null;
document.ondragstart = null;
document.onmousedown = null;
document.body.oncontextmenu = null;
document.body.onselectstart = null;
document.body.ondragstart = null;
document.body.onmousedown = null;
document.body.oncut = null;
document.body.oncopy = null;
document.body.onpaste = null;
</script>
Everytime I change my page, it keeps adding this script, so it stacks the same script over and over.
Do you guys have any ideas why this is happening?
I also searched entire code where it does add this script but couldn't find it.
I can give any informations you need, so please help me with this problem.
Many thanks!!!

Since this one is added only on Chrome and not Firefox, and looking at the code added, I guess that you can simply ignore that one and move along (something on your side and not directly related to Nuxt).

Related

Chrome extension to replace Twitter words

I'm trying to make a code extension that will replace one word with another on Twitter. There's code shared on GitHubfrom 2016 that says it should work, but is having no effect when I apply the extension in my browser. Can anyone help with the issue here? Has Twitter changed too much since this code was written for it to currently work, or is there another issue? When I upload the unpacked extension into Chrome it isn't detecting any errors, but I'm not getting any results.
(function() {
function replaceTwitterWord() {
var tweetContent = document.querySelectorAll(".tweet-text");
[].slice.call(tweetContent).forEach(function(el){
var newContent = el.innerHTML.replace(/OLD_WORD_NO_QUOTATION_MARKS/g,"NEW_WORD_IN_QUOTATION MARKS");
if (newContent != el.innerHTML) {
el.innerHTML = newContent;
}
});
}
function tick() {
replaceTwitterWord();
window.setTimeout(tick, 5000);
}
tick();
})();
Well, it seems like Twitter has changed plenty of things since then. At least there is no more elements having class '.tweet-text' so you have to get another tool.

Remove/Prevent .js file in JavaScript

Hi I am working with a webservice and I have to manipulate the design to make it look better. Recently I had to make it work on IPad.
So my Problem is my edit's don't work in Iphone because the service adds if its a mobile device a viewport and an extra .js file. This is causing unwanted changes. So is there a way to prevent the system from loading / opening? I can use Javascript to do this. My recent trys was to get the "IPhone.js" and make it empty
var scriptElements = document.getElementsByTagName("script");
var patt = /iPhone.js/g;
var sourceOfElement = "";
for (var i = 0; i < scriptElements.length; i++) {
sourceOfElement = scriptElements[i].src;
if (patt.test(sourceOfElement)) {
scriptElements[i].src = "";
};
This didn't really worked because the IPhone.js is loaded before I can "make it empty".
Another try was to remove the viewport, this also did't worked.
So anybody have any idea how to prevent the service from loading/executing the IPhone.js?
can you add iphone.js via javascript not script tag?
It will be something like this:
if (shouldILoad) {
(function() {
var myscript = document.createElement('script');
myscript.type = 'text/javascript';
myscript.src = ('iphone.js');
var s = document.getElementById('myscript');
s.parentNode.insertBefore(myscript, s);
})();
}
If you don't want iphone.js to execute just add a return statement at the start of the iphone.js file if condition is matched
iPhone.js
if(YOUR_CONDITION_NOT_TO_EXECUTE_IPHONE_JS) return; //check for your condition and return
//Other iphone.js code

document.getElementById always returns "null" for ribbons

I need to set the background color of one of the buttons in the form's ribbon. This isn't supported through Ribbon Workbench, so I have written following javascripts to achieve the same:
function setOpportunityRibbonsAppearance() {
var submitToForeCastButton = parent.document.getElementById("opportunity|NoRelationship|Form|sfw.opportunity.Button1.Button");
if (submitToForeCastButton != null) {
submitToForeCastButton.style.backgroundColor = "lightyellow";
}
}
I have registered this scripts in Form Load event. However the issue is that, I always get parent.document.getElementById as null only.
Surprisingly, I am able to see the control while running the parent.document.getElementById statement in the browser's console, and can also change the styling attributes.
Can anyone please suggest what could be wrong here?
P.S. - I understand document.getElementById is not recommended to use in CRM, however, I am left with no other choice while trying to change the appearance of some of the buttons.
Any help on this, will be much appreciated.
You could upload an icon with a yellow background, to keep everything supported. You won't see text on yellow but it might work for you. Easy and standard.
To keep it unsupported and ugly, you could just keep on trying until you make it, setInterval allows for a function to be repeated:
function setOpportunityRibbonsAppearance() {
var submitToForeCastButton = null;
var interval = setInterval(function(){
submitToForeCastButton = parent.document.getElementById("opportunity|NoRelationship|Form|sfw.opportunity.Button1.Button");
if(submitToForeCastButton != null) {
submitToForeCastButton.style.backgroundColor = "lightyellow";
clearInterval(interval);
}
}, 500); // Every 500ms. Adjust as needed, not too fast or browser will choke.
}
Its probably because your script is running before the page is fully loaded.
Try adding a delay to the to the function Put a Delay in Javascript

How to reset variables state when moving between pages (Chrome Specific)?

I am working with the html5 history api. When I click a link to a new page, and then click the back button. I am seeing variables who are retaining their state between page loads.
Example:
(function(namespace){
var singlePageSessionId = 0;
singlePageSessionId = new Date().getTime();
namespace.SinglePageSessionId = function(){
return singlePageSessionId;
}
}(window.namespace = window.namespace || {}))
That singlePageSessionId variable should be set once per actual page load. However when I click back, and then check the value of namespace.SinglePageSessionId it retains the timestamp of when I first navigated to the site. Since I am re-executing the javascript I expect the variable to be reset.
I either have a fundamental mis-understanding of how the javascript engine works between pages or there is some weird behavior here.
Is there a way to make sure the variables get reset ?
How hard I tried I could not reproduce the issue you are talking about.
Locally I had no problem at all going back and receive new value.
This is what I did http://jsfiddle.net/itaymer/bqg3azx8/
(function(namespace) {
var singlePageSessionId = new Date().getTime();
namespace.SinglePageSessionId = function(){
return singlePageSessionId;
}
}(window.namespace = window.namespace || {}));
document.querySelector(".pageSessionId").innerHTML = window.namespace.SinglePageSessionId();
Maybe you failed to supply the whole situation information?

ABCPdf add document javascript

Is it possible to add document JavaScripts to a generated PDF using ABCPdf?
If you mean, Javascript that is being executed after the document has been loaded, then have a look at this documentation page.
doc.HtmlOptions.UseScript = true;
doc.HtmlOptions.GeckoSubset.OnLoadScript =
#"(function() {
window.ABCpdf_go = false;
// your javascript code here
window.ABCpdf_go = true;
})();";
I think you should be able to. There are some settings in the c# which will help.
You need to set the
doc.HtmlOptions.UseScript = true;
this will enable javascript to run.
it's probably worth setting the timeout to give it more time to finish loading
doc.HtmlOptions.Timeout = 10000;
and i've always had better results with the gecko rendering engine
doc.HtmlOptions.Engine = EngineType.Gecko;

Categories