I'm a blogger and I monetize my blog with adsense. While coding or in fact adding asynchronous code inside <head></head>tag of my blog it appears that I have to add it like this:
<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
instead of like this:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
Otherwise it will show me an error. Can anyone explain why? Do you know if I'm allowed to add this (according to adsense)?
Use this code instead on any of them... I'm currently using this...Try it
<script async='async' src='http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'></script>
You're writing an XHTML document (either because of the Content-Type or an XML declaration).
Therefore, the entire document must be valid XML.
Unlike regular HTML, all XML attributes must have values.
I have a solution for the same problem with Hubspot Tracking Code with Blogger.
When adding the following code to the theme HTML in Blogspot, I get an error.
Error parsing XML, line 2490, column 62: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.
<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/xxxxxx.js"></script>
<!-- End of HubSpot Embed Code -->
I fixed it be using the above fix changing async defer to async="async defer"
<!-- Start of HubSpot Embed Code 17/03/2017-->
<script type="text/javascript" id="hs-script-loader" async="async defer" src="//js.hs-scripts.com/2336222.js"></script>
<!-- End of HubSpot Embed Code -->
Related
According to the docs, all I need to do is to wrap the block I'd like to "talk to" via Javascript with this:
<amp-script layout="container" src="language-toggle.js">
// Some basic HTML
</amp-script>
The Javascript file is there, I tested with a simple console.log. Yet the amp-script tag has opacity: 0.7 (AMP default style). Apparently, it needs the class i-amphtml-hydrated to be fully visible. I've been trying to wrap my head around this for a few hours now, even Google could not help me with this.
There are a bunch of ServiceWorker errors in the console, which are also all generated by AMP. I have no idea why they appear or how to get rid of them. This whole AMP thing is a mess for me.
These are the AMP scripts I currently added:
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>
Carousel and YouTube are working fine.
Could anybody please shed some light onto this?
I highly recommend to enable AMP development mode by adding #development=1 to the URL.
Relative URL's are not allowed in the src attribute of the amp-script tag (the development parameter would have told you that).
You can have something like this though:
<amp-script width="1" height="1" script="demo"></amp-script>
<script type="text/plain" target="amp-script" id="demo">
console.log('Foobar');
</script>
But you will need a matching hash in a meta tag in your head:
<head>
...
<meta
name="amp-script-src"
content="sha384-hash"
/>
</head>
Again, the development parameter will tell you the hash you should use, although you could also disable hash checks during development.
All of the above will still not hydrate your amp-script element. In order for your element to be hydrated, the script has to actually to something to the DOM, like for example adding a div on a button click:
<amp-script layout="container" script="demo">
<button id="hello">Add headline</button>
</amp-script>
<script type="text/plain" target="amp-script" id="demo">
console.log('Foobar');
const button = document.getElementById('hello');
button.addEventListener('click', () => {
const h1 = document.createElement('h1');
h1.textContent = 'Hello World!';
document.body.appendChild(h1);
});
</script>
Be aware that you are quite limited with what you are allowed to do. For example, the above snippet will not work without the event listener, so you can not simply add an element without user interaction.
The messages regarding the references can safely be ignored - the AMP examples do exaclty the same, the AMP still passes the validation.
I'm building a Seaside application and I'm searching for a way to highlight some code snippets on the browser with JS.
I found highlight.js which support Smalltalk syntax but it doesn't work.
I add this script and hljs.initHighlightingOnLoad(); in the header but it doesn't work.
Probably I miss something but what?
I use highlight.js from CDN:
<link href='http://yandex.st/highlightjs/8.0/styles/sunburst.min.css' rel='stylesheet'/>
<script src='http://yandex.st/highlightjs/8.0/highlight.min.js' type='text/javascript'/>
I also define a format function like:
function format(){
var b=document.getElementsByTagName("pre");
for (i=0;i<b.length;i++) {
hljs.tabReplace = ' '; // 2 spaces
b[i].style.fontSize = '0.9em';
hljs.highlightBlock(b[i],' ',false);
}
}
and use
<pre class="smalltalk"><code>……</code></pre>
for highlightable block. Then I call format() when the page is loaded (or a dynamic content with code is loaded into page)
I've got Google+ button on my site. It works fine, but W3C validator shows error:
The text content of element script was not in the required format:
Expected space, tab, newline, or slash but found < instead.
Here is the code:
<script src="https://apis.google.com/js/platform.js" async defer>lang:"pl";</script>
How can I fix this?
The W3C validator is complaining about the contents of <script src...> tag. According to these specs, a script tag with src attribute can only contain whitespace and/or JavaScript comments.
You can use the following syntax instead:
<script>
window.___gcfg = { lang: "pl" };
</script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
Hello I have a JavaScript code and I want to use it in ASP file but my error code says:
Active Server Pages error 'ASP 0138'
Nested Script Block
/reklamsag.html, line 3
A script block cannot be placed inside another script block.
My code is:
<script src="http://ad.reklamport.com/scripts/rp.js" type="text/javascript"></script>
<script type="text/javascript">
document.write("<script src='http://ad.reklamport.com/rpgetad.ashx?tt=t_canvecan_anasayfa_300x250&ciid=&rnd="+Math.random()%99999999+"'></"+"script>");
</script>
Someone says use code in external file and include it asp file i use this include code but it didn't work:
<!--#include file="reklamsag.html"-->
There is a technique to split the word "<script" into two parts such as "<scr" and "ipt" .
document.write("<scr"+"ipt src....></scr"+"ipt>");
Your code can go like this:
<script src="http://ad.reklamport.com/scripts/rp.js" type="text/javascript"></script>
<script type="text/javascript">
document.write("<scr"+"ipt src='http://ad.reklamport.com/rpgetad.ashx?tt=t_canvecan_anasayfa_300x250&ciid=&rnd="+Math.random()%99999999+"'></"+"scr"+"ipt>");
</script>
That's an incorrect way to load external JavaScript.
I understand the reasoning behind this is to prevent caching, since you already have server side language at your disposal, just have this and it will have the desired effect:
<script type="text/javascript" src="http://ad.reklamport.com/rpgetad.ashx?tt=t_canvecan_anasayfa_300x250&ciid=&rnd=<%=CLng(Timer())%>"></script>
This will append the amount of seconds since 12 AM, which is pretty much the same as random number. If you want extra layer or "uniqueness" you can add year, month and day.
I'm using jQuery-templates for the first time, and I need my template to include some javascript, so it it run when the template is rendered.
I need at timestamp for the current time...
Writing
<script type="text/javascript"></script>
in a template, renders it to fail.
Is this simply not possible?
the following was blatantly copied from my answer to another question
When the HTML parser finds <script> it will start parsing the contents until it finds </script> which is present in:
document.write("<script src='links7.js?'+Math.random()+></script>
As such, you'll need to change the source so that it's not parsed as the end of a script element:
document.write("<script src='links7.js?'+Math.random()+></scri" + "pt>");
Ideally, you'd have HTML escaped all your inline JavaScript code, which would also mitigate this issue:
document.write("<script src='links7.js?'+Math.random()+></script&
For your particular case (which is different enough for me to not mark as a dupe), make sure that your content between your script tags is HTML escaped, or correctly placed between <![CDATA[ ]]> tags.
<script type="text/javascript"></script>
-or-
/* <![CDATA[ */
<script type="text/javascript"></script>
/* ]]> */
That all being said, you should be calling the necessary JS during the rendering process, and not injecting a script element into the DOM unnecessarily.