Dean Elliott
Dean Elliott

Reputation: 1533

Any ideas why this bookmark script isn't working in IE?

I've been asked to figure out why a Javascript bookmark script isn't working in IE. Javascript isn't my forte so I'm a bit lost.

Any ideas?

The script in use is as follows

<script type="text/javascript">

/* Modified to support Opera */
function bookmarksite(title,url){
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    } 
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}
</script>

Thanks in advance.

Upvotes: 0

Views: 328

Answers (2)

user1619962
user1619962

Reputation: 374

It appears that the AddFavorite method in IE8 has been restricted to only trigger with a user event,

not an automatic event like onload or onunload. try this

<a onclick = "bookmarksite('stackoverflow','http://stackoverflow.com')">BookMark</a>

Upvotes: 1

Salketer
Salketer

Reputation: 15711

This code seems to be working fine. Make sure the URL is a valid http url or else you will get an access denied error in IE (maybe other browser too though).

Upvotes: 0

Related Questions