I have written some javascript functions and saved the file as dashboardjs.jsp. The reason why the file is made as jsp is that i wanted to use struts2 tag inside the scripts. Now i call this script in a script tag as follows:
<script type="text/javascript" src="/dashboardjs.jsp"></script>
After loading this script i am just trying to call a function in the above script on load
<script type = "text/javascript">
$(function(){
getTrend(id,true,false); //this function is defined in dashboardjs.jsp
});
</script>
The above works completely fine in FF,Chrome but in IE it throws error saying getTrend is undefined. In IE developer tool (network tab) it shows that the call to the script dashboardjs.jsp is made multiple times. My question is why IE is behaving in this way? Is there any solution for this problem? Please suggest.
Related
I've been trying to embed an external JavaScript source into my Next.js application and keep receiving following error:
Failed to execute 'write' on 'Document': It isn't possible to write
into a document from an asynchronously-loaded external script unless
it is explicitly opened.
The code I am trying to use can be found here - The map with the vessel has an option to embed it. So far the component that generates this error looks like this:
<div className={styles['container']}>
<Script type="text/javascript">
var width="100%";var height="400"; var mmsi=228402900;
</Script>
<Script
type="text/javascript"
src="https://www.vesselfinder.com/aismap.js">
</Script>
</div>
If I copy the embed code into CodePen it works just fine - link to my codepen with the embedded map here.
Does somebody know what could be the problem here?
The issue occurs because the external script is being loaded asynchronously by next/script, thus ignoring the document.write() call present in the script.
From Document.write() MDN documentation:
Note: Using document.write() in deferred or asynchronous scripts will
be ignored and you'll get a message like "A call to document.write()
from an asynchronously-loaded external script was ignored" in the
error console.
You'll need to set the Script strategy to beforeInteractive so the script is added to <head>, and explicitly set the defer property to false to prevent the script from being loaded asynchronously.
<Script
type="text/javascript"
src="https://www.vesselfinder.com/aismap.js"
strategy="beforeInteractive"
defer={false}
></Script>
Update: I am encountering this issue only with the chrome browser for some reason.
I have in my html head tag a java script that I load using the following statement:
<script type="text/javascript" src="script.js"></script>
I am also loading the ReCaptcha java script using the following:
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
In the body of my html code, I am calling the following ReCaptcha Code:
<div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="Key"></div>
If I execute the code locally (i.e. on my development computer), everything works fine. Meanwhile, if I publish my Site to a Server, the data-callback function, which is in my script.js file loaded as explained above, does't get called.
Why is this happening?
I loaded jquery.min.js in head tag using script tag as below. this version was 1.2.6.
<script type="text/javascript" src="JS/jquery.min.js?v=1.2.6"></script>
<script type="text/javascript" src="JS/jquery-migrate-3.0.0.min.js"></script>
Then I cleared cache and loaded page (that one is ASPX)
So above jquery.min.js?v=1.2.6 is cached in browser now.
Migrate plugin is 3.0.0 which has issue with this version of jQuery.
So I changed content of (I know I can use different path anyway) jquery.min.js from 3.2.1 jQuery file and script tag changed to
<script type="text/javascript" src="JS/jquery.min.js?v=3.2.1"></script>
I reloaded same page at that time also it gives error of migrate plugin. in console also error is in JS/jquery.min.js?v=1.2.6
When I reload it second time (without clearing cache) , then it is not showing error anymore and also if I clear cache at first time then also error is not present.
What's wrong am I doing?
Here it doesn't matter which error it is but only matters is why it is occurring even after querystring is different.
I research on google before post on Stackoverflow,,
But all problem that i have found are different then my problem.
I am Developing Chrome Extension and load JS from JS...
I am placing an ad script into HTML head..
if i write a script manually in HTML head
<script src="Ads_URL"></script>
Its Working ads show..
.
But if i append script throung Jquery or Pure javascript
its return Warning
$("head").append("Google Analythic Script"); // Working
$("head").append("<script src="Ads_URL"></script>");//Return warning
Failed to execute 'write' on 'Document': It isn't possible to write
into a document from an asynchronously-loaded external script unless
it is explicitly opened.
Any solution?
Update
This question is not duplicate.. Link in first comment is not helpful for me..
In that question #jfriend00 is using document.write("<span>");
If i use document.write() function, Ads show, but remove all tags from body and just <script> is left "document.write() Clear the body"
Here is my script that i want to inject
<script data-cfasync=false src='//s.ato.mx/p.js#id=21352&size=300x250'></script>
Did you tried this: chrome.tabs.executeScript? This didn`t add script in html but execute same as console. You can try to get contents of remote javascript code as a string and execute it.
I am using head.js and using the below file to initiate the javascript file calls:
<script src="/scripts/load.js" type="text/javascript"></script>
In the load.js file I have the following code:
head.js(
{livechat: "/scripts/livechat.js"},
{jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"},
{jquerytools: "http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"},
{slider: "/scripts/jquery.nivo.slider.pack.js"},
{prettyphoto: "/scripts/jquery.prettyPhoto.js"},
{sliderfunctions: "/scripts/slidercode.js"},
{functions: "/scripts/functions.js"}
);
My problem is, even though I removed the livechat line, the chat box is still appearing on all my website pages unless I manually clear the browser cache. My concern is that I no longer utilize the livechat service and I do not want the visitors to be confused by seeing the livechat box appear but not function correctly.
Is there any way to tell head.js that there has been a change in the files being loaded and to refresh browser cache or something?
You could put something along the lines of this:
<script src="/scripts/load.js?date=123456789" type="text/javascript"></script>
Adding a query string to this file should trick the browser into thinking it's something it hasn't seen before.