Results 1 to 3 of 3

Thread: Why does this script work in Firefox but not work in IE?

  1. #1
    Join Date
    Mar 2009
    Location
    RTP, NC
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Why does this script work in Firefox but not work in IE?

    As a parallel thread to my earlier one about bookmarking URLs, this post is the source of the trouble that I am trying to solve with my previous post. If I cannot find any help with that post, perhaps someone can help me solve this issue?

    I inherited the following script from an app and it works just fine in FireFox, but not in IE. If you have any insights to share on why this is the case and what I could do to make it work in both realms please share them.

    Here is the Jscript that works fine in FireFox:

    function addbookmark(){
    if (document.all) {
    window.external.AddFavorite(window.location.href,document.title);
    } else {
    alert("Use CTRL-D to add a bookmark in your Browswer.");
    }}
    function land(ref, target)
    {
    lowtarget=target.toLowerCase();
    if (lowtarget=="_self") {window.location=loc;}
    else {if (lowtarget=="_top") {top.location=loc;}
    else {if (lowtarget=="_blank") {window.open(loc);}
    else {if (lowtarget=="_parent") {parent.location=loc;}
    else {parent.frames[target].location=loc;};
    }}}
    }


    This is how it is called from the XHTML:
    <a href="javascript:addbookmark()"><img src="images/bookmark.gif"" /></a>

    This is in the head section of the pages that use the script:
    <script language="JavaScript" type="text/javascript" src="Jscript/bookmark.js"></script>

    The only thing this little script does is create a popup window with the alert text in it. The message that IE gives the viewer is "Error on page." The popup blocker is turned off.

    All comments and thoughts are welcome!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,028
    Thanks
    44
    Thanked 3,210 Times in 3,172 Posts
    Blog Entries
    12

    Default

    The only code being used is:

    Code:
    function addbookmark(){
    if (document.all) {
    window.external.AddFavorite(window.location.href,document.title);
    } else {
    alert("Use CTRL-D to add a bookmark in your Browswer.");
    }}
    IE and Opera both support document.all - so will attempt:

    Code:
    window.external.AddFavorite(window.location.href,document.title);
    I believe that will give an error in IE if the page is local. Perhaps even with a live page. In Opera, there is no window.external.AddFavorite, so there will just be an error, but Opera is usually silent when it encounters script errors.

    All others presumably will do:

    Code:
    alert("Use CTRL-D to add a bookmark in your Browswer.");
    If that's all that you want to have happen anyway, just change the function to:

    Code:
    function addbookmark(){
    alert("Use CTRL-D to add a bookmark in your Browswer.");
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2009
    Location
    RTP, NC
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you John - your suggestion has solved my problem beautifully (at least on first pass).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •