我有这个嵌入了js的html页面
<html xmlns="http://www.w3.org/1999/xhtml"> <title>Versions: 1.0.715 vs. 1.0.715 [ route HISTORIC_TIME ]</title> <head> <script type="script"> function createBase() { var str1 = window.location.href; alert("check"); var base = document.createElement('base'); base.href = str1; document.getElementsByTagName('head')[0].appendChild(base); } window.onload = createBase; </script> </head> <body style=""> <div class="content-background" style="background-color: #4285f4; height: 398px; position: absolute; width: 100%; top: 60px; z-index: -1;"></div> </body> </html>我尝试使用当前url添加<base>标记。 但是,我刷新页面,并且警报未显示,并且未创建<base>标记。
这是为什么?
I have this html page with js embedded in it
<html xmlns="http://www.w3.org/1999/xhtml"> <title>Versions: 1.0.715 vs. 1.0.715 [ route HISTORIC_TIME ]</title> <head> <script type="script"> function createBase() { var str1 = window.location.href; alert("check"); var base = document.createElement('base'); base.href = str1; document.getElementsByTagName('head')[0].appendChild(base); } window.onload = createBase; </script> </head> <body style=""> <div class="content-background" style="background-color: #4285f4; height: 398px; position: absolute; width: 100%; top: 60px; z-index: -1;"></div> </body> </html>I try to add a <base> tag with the current url. However I refresh the page and the alert is not shown plus the <base> tag isn't created.
Why is that?
最满意答案
<script type="script">
script不是已注册的MIME类型。 它不是我所知道的任何浏览器支持的编程语言。 由于浏览器不知道该语言,因此不会尝试执行该语言。
JavaScript的正确MIME类型是application/javascript (或旧式浏览器的text/javascript )。
从HTML 5开始, type属性是可选的,并且在编写JavaScript时应该完全省略(因为它浪费了字节并提供了打破输入错误代码的机会)。
<script type="script">
script is not a registered mime type. It is not a programming language supported by any browser that I'm aware of. Since the browser don't know the language, it doesn't try to execute it.
The correct mime type for JavaScript is application/javascript (or text/javascript for legacy browsers).
As of HTML 5, the type attribute is optional and should be omitted entirely when writing JavaScript (since it is a waste of bytes and offers the opportunity to break code with typos).
window.onload不会调用,也不会创建一个``我有这个嵌入了js的html页面
<html xmlns="http://www.w3.org/1999/xhtml"> <title>Versions: 1.0.715 vs. 1.0.715 [ route HISTORIC_TIME ]</title> <head> <script type="script"> function createBase() { var str1 = window.location.href; alert("check"); var base = document.createElement('base'); base.href = str1; document.getElementsByTagName('head')[0].appendChild(base); } window.onload = createBase; </script> </head> <body style=""> <div class="content-background" style="background-color: #4285f4; height: 398px; position: absolute; width: 100%; top: 60px; z-index: -1;"></div> </body> </html>我尝试使用当前url添加<base>标记。 但是,我刷新页面,并且警报未显示,并且未创建<base>标记。
这是为什么?
I have this html page with js embedded in it
<html xmlns="http://www.w3.org/1999/xhtml"> <title>Versions: 1.0.715 vs. 1.0.715 [ route HISTORIC_TIME ]</title> <head> <script type="script"> function createBase() { var str1 = window.location.href; alert("check"); var base = document.createElement('base'); base.href = str1; document.getElementsByTagName('head')[0].appendChild(base); } window.onload = createBase; </script> </head> <body style=""> <div class="content-background" style="background-color: #4285f4; height: 398px; position: absolute; width: 100%; top: 60px; z-index: -1;"></div> </body> </html>I try to add a <base> tag with the current url. However I refresh the page and the alert is not shown plus the <base> tag isn't created.
Why is that?
最满意答案
<script type="script">
script不是已注册的MIME类型。 它不是我所知道的任何浏览器支持的编程语言。 由于浏览器不知道该语言,因此不会尝试执行该语言。
JavaScript的正确MIME类型是application/javascript (或旧式浏览器的text/javascript )。
从HTML 5开始, type属性是可选的,并且在编写JavaScript时应该完全省略(因为它浪费了字节并提供了打破输入错误代码的机会)。
<script type="script">
script is not a registered mime type. It is not a programming language supported by any browser that I'm aware of. Since the browser don't know the language, it doesn't try to execute it.
The correct mime type for JavaScript is application/javascript (or text/javascript for legacy browsers).
As of HTML 5, the type attribute is optional and should be omitted entirely when writing JavaScript (since it is a waste of bytes and offers the opportunity to break code with typos).
发布评论