3

I am trying to make a default homepage script using the famous script for IE but I'm trying to add it in a jquery function.

So this works:

<a href="#" onClick="document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.google.com');">
    Click here to make My Site your default homepage
  </a>

but this doesn't:

<a href="#" onClick="">
    Click here to make My Site your default homepage
  </a>

$('a').click(function() {

 document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.google.com');

});

What I'm I doing wrong?

EDIT: Please note the on click function doesnt work for IE9. IE6,7 and 8 it works.

jQuerybeast
  • 14,130
  • 38
  • 118
  • 196

4 Answers4

1

Your code works fine in IE (tested in IE 7). Check DEMO here.

But it seems like you cannot do the same in FF. Read about it here

Alternatively, you can provide an instruction in FF on how to change.. See DEMO here

Community
  • 1
  • 1
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
  • IE9, doesnt work sir. I am not interested IE6 and 7. Thank you. I was aware of that and I should point it. – jQuerybeast Jan 19 '12 at 21:22
  • Maybe (hopefully) they completely removed this anti-feature in IE9... in this case it wouldn't be possible anymore at all. – ThiefMaster Jan 20 '12 at 01:12
1

With jQuery 1.7 use the .on() function:

$(document).ready(function() {

    $("a").on("click", function(event){
       document.body.style.behavior='url(#default#homepage)';
       document.body.setHomePage('http://www.google.com');

    });
});

jsFiddle: http://jsfiddle.net/nKkNV/

jQuerybeast
  • 14,130
  • 38
  • 118
  • 196
0

By using this: $('a') you are targeting all links on the page.

Try giving the anchor tag an id attribute, then change your jQuery selector to look for that attribute, like this (also remove the onClick attribute altogether):

<a href="#" id="makeDefault">
    Click here to make My Site your default homepage
  </a>

$('a#makeDefault').click(function() {
  document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.google.com');
});
Christopher Scott
  • 2,383
  • 2
  • 25
  • 23
-2

One thing you are doing wrong in both versions is that you have a link with link text “Click here to make My Site your default homepage” that points to the start of the current page.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390