简体   繁体   English

如果页面是index.html,如何运行jquery脚本

[英]How to run jquery script if page is index.html

How to run jquery script if page is index.html. 如果页面是index.html,如何运行jquery脚本。 When I entered URL in browser like http://qubedns.co.in/ is will automatically execute but not show the home page name (default). 当我在浏览器(如http://qubedns.co.in/ )中输入URL时,它将自动执行,但不显示主页名称(默认)。 Not show like http://qubedns.co.in/index.html 不显示为http://qubedns.co.in/index.html

I want the current page name when user hit the url http://qubedns.co.in/ to run some script. 当用户点击url http://qubedns.co.in/来运行某些脚本时,我想要当前的页面名称。 If I get the page name 'index/html' I will finish it. 如果获得页面名称“ index / html”,则将其完成。

I used for other page 我用于其他页面

var currPageView = document.location.pathname.match(/[^\/]+$/)[0];
if(currPageView == 'index.html')
{
  // My Script here
}

I have try with: 我尝试过:

var currPageView;
if($(location).attr('href')=='http://qubedns.co.in'){
    currPageView == window.location.host + '/' + 'index.html';
}else{
    currPageView = document.location.pathname.match(/[^\/]+$/)[0];
}

Is it right? 这样对吗? any others solution ? 还有其他解决方案吗?

if your trying like this then you will get total url 如果您这样尝试,那么您将获得总网址

$(location).attr('href');

can you try like this ...and check this link also 你可以这样尝试...并检查此链接吗

http://en.proft.me/2014/08/1/how-work-location-url-javascript-jquery-angularjs/ http://en.proft.me/2014/08/1/how-work-location-url-javascript-jquery-angularjs/

var currPageView;
if($(location).attr('hostname')=='http://qubedns.co.in'){
currPageView == window.location.hostname + '/' + 'index.html';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有谁知道每次打开 index.html 页面时如何自动运行 .json 文件中的脚本? - Does anyone know how to run the script in the .json file automatically everytime I open my index.html page? Index.html 脚本标记值在运行时被替换 - Index.html Script Tag Values Replaced On Run GWT ScriptInjector VS将脚本标记添加到index.html页面 - GWT ScriptInjector VS adding script tag to index.html page 仅在index.html页面上运行函数(Javascript) - Run function only on index.html page (Javascript) 如何读取angular index.html文件中的local Storage JSON并显示在View page source as a script - How to read local Storage JSON in angular index.html file and show in View page source as a script 如果没有 index.html,如何在 index.html 中运行脚本 - How to run scripts in index.html in react if you don't have index.html 如果html页面是主页,如何运行jquery脚本...? - How to run jquery script if html page is the home page…? 如何使用angularJS将脚本动态添加到index.html? - How to dynamically add the script to index.html using angularJS? 如何删除index.html和karma中加载的脚本文件中的重复项? - How to remove duplication in the script files loaded in index.html and karma? 如何在脚本标签的index.html中使用Bowser Javascript库? - How to use a Bowser Javascript Library in index.html in script tags?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM