Javascript jQuery排除特定页面的document.ready事件
我有以下代码:Javascript jQuery排除特定页面的document.ready事件,javascript,jquery,iframe,Javascript,Jquery,Iframe,我有以下代码: $(document).ready(function() { $(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>"); }); $(文档)
$(document).ready(function() {
$(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
});
$(文档).ready(函数(){
$(“.rightImage”).last().append(“”);
});
上面的代码向类添加了一个iframe,问题是它出现在每个页面上。除了我的主页外,有没有一种方法可以过滤掉上面的功能,使其在每个页面上都能正常工作?
我无法控制家长的html,所以我必须这样做
谢谢您可以使用
窗口。位置
请尝试:
$(document).ready(function() {
if(window.location !== "homepageurl"){
$(".rightImage").last().append("<iframe src='http://images.findel-education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
}
});
$(文档).ready(函数(){
如果(window.location!=“homepageurl”){
$(“.rightImage”).last().append(“”);
}
});
检查窗口。位置
并执行文档中的步骤。如果不匹配,准备就绪
$(document).ready(function () {
if (window.location != "exceptionURL") {
$(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
}
});
$(文档).ready(函数(){
if(window.location!=“exceptionURL”){
$(“.rightImage”).last().append(“”);
}
});
添加带有url的筛选器
$(document).ready(function() {
if(window.location.href!='http://yourhomepage'){
$(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
}
});
$(文档).ready(函数(){
如果(window.location.href!='http://yourhomepage'){
$(“.rightImage”).last().append(“”);
}
});
好吧,试试这个:
$(document).ready(function() {
if (document.location.href != 'homepage_url') {
$(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
}
});
$(function(){
if(!location.pathName.contains('home')){
$(".rightImage").last().append("<iframe .... height='250px'></iframe>");
}
});
$(文档).ready(函数(){
如果(document.location.href!='homepage\u url'){
$(“.rightImage”).last().append(“”);
}
});
您可以查看url:
$(document).ready(function() {
if(window.location.href.indexOf('http://www.example.com') != 0) {
$(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
}
});
$(文档).ready(函数(){
if(window.location.href.indexOf('http://www.example.com') != 0) {
$(“.rightImage”).last().append(“”);
}
});
如果当前url以“”开头,则不会执行以下代码,否则将附加代码。您可以尝试以下操作:
$(document).ready(function() {
if (document.location.href != 'homepage_url') {
$(".rightImage").last().append("<iframe src='http://images.findel- education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");
}
});
$(function(){
if(!location.pathName.contains('home')){
$(".rightImage").last().append("<iframe .... height='250px'></iframe>");
}
});
$(函数(){
如果(!location.pathName.contains('home')){
$(“.rightImage”).last().append(“”);
}
});
检查url中是否有与主页相关的特定单词