admin管理员组

文章数量:1323714

I have the below code :

$(document).ready(function() {
   $(".rightImage").last().append("<iframe src='     education.co.uk/EmailSignup/website_email_sign_up.html' width='180px'frameborder='0' height='250px'></iframe>");  
});

The above code adds an iframe to a class, the problem is it appears on every page. Is there a way to filter out the above function to work on every page except my homepage? I don't have control of the parent's html so that's why I have to do it this way.

Thanks

I have the below code :

$(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>");  
});

The above code adds an iframe to a class, the problem is it appears on every page. Is there a way to filter out the above function to work on every page except my homepage? I don't have control of the parent's html so that's why I have to do it this way.

Thanks

Share Improve this question edited Mar 14, 2014 at 11:26 Zaheer Ahmed 28.6k12 gold badges76 silver badges112 bronze badges asked Mar 14, 2014 at 11:25 user3120015user3120015 1814 gold badges6 silver badges18 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 2

Well, try this:

$(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>"); 
    } 
});

You can use window.location try:

$(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>");  
  }
});

check the window.location and execute the steps in the document.ready if its not a match

    $(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>");
        }
    });

add a filter with the 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>");  
       }
    });

You can check the url:

$(document).ready(function() {
    if(window.location.href.indexOf('http://www.example.') != 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>");  
    }
});

If the current url starts with 'http://www.example.' it wont execute the following code, else it will append the code.

You can try this:

$(function(){
    if(!location.pathName.contains('home')){ 
        $(".rightImage").last().append("<iframe .... height='250px'></iframe>");
    }
});

check if related a specific word about your home page is available in the url.

本文标签: javascriptjQuery excluding documentready event for a specific pageStack Overflow