没有Javascript检测脚本+;重新使用

没有Javascript检测脚本+;重新使用,javascript,redirect,Javascript,Redirect,我想编写一个脚本来检测用户是否禁用了javascript,如果禁用了,则将其重定向到另一个页面(比如mysite.com/enablejavascript) 然而,我不知道从哪里开始!非常感谢。当java脚本被禁用时,您希望如何编写脚本 这是不可能做到的。使用禁用javascript时,可以显示一条消息 标记: HTML NoScript元素()定义了当页面上的脚本类型不受支持或当前在浏览器中关闭脚本时要插入的HTML部分 Gdoron已经提到了noscript。如果用户禁用了JavaScrip

我想编写一个脚本来检测用户是否禁用了javascript,如果禁用了,则将其重定向到另一个页面(比如mysite.com/enablejavascript)


然而,我不知道从哪里开始!非常感谢。

当java脚本被禁用时,您希望如何编写脚本

这是不可能做到的。使用
禁用javascript时,可以显示一条消息

标记:

HTML NoScript元素()定义了当页面上的脚本类型不受支持或当前在浏览器中关闭脚本时要插入的HTML部分


Gdoron已经提到了noscript。如果用户禁用了JavaScript,您可以与ª一起重定向用户

JavaScript重定向可以通过以下方式完成


位置。替换('http://example.com/with-js');
noscript+元刷新的示例:

1) 注意维基百科文章的那一部分

元刷新标记有一些缺点:

  • 如果页面重定向过快(少于2-3秒),使用下一页上的“后退”按钮可能会导致某些浏览器移回重定向页面,从而再次发生重定向。这对可用性是不利的,因为这可能会导致读者“卡在”最后一个网站上
  • 读者可能希望也可能不希望被重定向到不同的页面,这可能会导致用户不满或引起安全问题

试试这个:如果java脚本被禁用,那么显示一个php链接

<script type="text/javascript">

document.write("<button type='button' onclick='somefunction()' >Some Text</button>"); 

</script>

<noscript> 

<?php echo "<a href='redirectfile.php'>Some Text</a>"; ?> 

</noscript>

写一些文字;

您应该将HTML重定向合并到noscript元素中。我找到了这个发电机。以下是您的示例代码:

<!-- Pleace this snippet right after opening the head tag to make it work properly -->

<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by http://insider.zone/tools/client-side-url-redirect-generator/ -->

<!-- REDIRECTING STARTS -->
<link rel="canonical" href="https://yourdomain.com/"/>
<noscript>
    <meta http-equiv="refresh" content="0;URL=https://yourdomain.com/">
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
    var url = "https://yourdomain.com/";
    if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
    {
        document.write("redirecting..."); // Don't remove this line or appendChild() will fail because it is called before document.onload to make the redirect as fast as possible. Nobody will see this text, it is only a tech fix.
        var referLink = document.createElement("a");
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    }
    else { window.location.replace(url); } // All other browsers
</script>
<!-- Credit goes to http://insider.zone/ -->
<!-- REDIRECTING ENDS -->

变量url=”https://yourdomain.com/";
if(typeof IE_fix!=“undefined”)//IE8和更低版本的补丁传递http引用
{
document.write(“重定向…”);//不要删除此行,否则appendChild()将失败,因为它是在document.onload之前调用的,以使重定向尽可能快。没有人会看到此文本,这只是一个技术修复。
var referelink=document.createElement(“a”);
referelink.href=url;
document.body.appendChild(referelink);
referelink.click();
}
else{window.location.replace(url);}//所有其他浏览器

您需要使用
@BrianDriscoll。你为什么不写个答案?它拥有最多的选票!如果禁用JavaScript,您将如何使脚本运行?+1。我不知道那件事。美好的我给你的答案增加了缺点。希望你不介意这对我来说似乎很好。然而VisualStudio声称noscript不能嵌入head中,meta不能嵌入noscript中。我的DOCTYPE是,html标记的名称空间是这些相关的吗?HTML5允许在文档中的任何位置使用元标记。它们在schema.org上用于微数据。HTML5还允许在头部使用noscript,只要它只包含meta等内容。请注意,meta刷新不推荐用于可访问性,这通常是某些人可能没有打开javascript的原因。请对您的解决方案进行更多描述。参考:
<!-- Pleace this snippet right after opening the head tag to make it work properly -->

<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by http://insider.zone/tools/client-side-url-redirect-generator/ -->

<!-- REDIRECTING STARTS -->
<link rel="canonical" href="https://yourdomain.com/"/>
<noscript>
    <meta http-equiv="refresh" content="0;URL=https://yourdomain.com/">
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
    var url = "https://yourdomain.com/";
    if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
    {
        document.write("redirecting..."); // Don't remove this line or appendChild() will fail because it is called before document.onload to make the redirect as fast as possible. Nobody will see this text, it is only a tech fix.
        var referLink = document.createElement("a");
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    }
    else { window.location.replace(url); } // All other browsers
</script>
<!-- Credit goes to http://insider.zone/ -->
<!-- REDIRECTING ENDS -->