locked
Need a link to bookmark page in master page RRS feed

  • Question

  • User50862095 posted

    I have two javascripts I need to put on the Master Page.  One is for printing the page, and the other is for bookmarking the page. 

    I tried just adding the scripts as I would have on Classic ASP.  The print script works, but the Bookmark script doesn't, even if I hardcode the page to bookmark.  Passing the page name makes this script a bit more challenging. 

    I tried registering the scripts and neither script works.  

    I'm content to leave the print script as I originally had it, but how do I get the bookmark script working?

    I tried:

    <script language="javascript" type="text/javascript" >
    <!--
        function CreateBookmarkLink(sTitle, sUrl) {
       
            if (window.sidebar) {
                // Mozilla Firefox Bookmark
                window.sidebar.addPanel(sTitle, sUrl,"");
            }
            else if( window.external ) {
                // IE Favorite
                window.external.AddFavorite(sUrl, sTitle);
            }
            else if(window.opera && window.print) {
                // Opera Hotlist
                return true;
            }
        }
    //-->
    </script>

    and

    <a href="javascript:CreateBookmarkLink('Write A Prisoner>',
                                     '<%# Eval(Request.ServerVariables("SCRIPT_NAME") & "?" & Request.ServerVariables("QUERY_STRING"))%>');">Bookmark</a>

    I couldn't get the variables passed, so I tried this:

    <a href="javascript:CreateBookmarkLink('Write A Prisoner','Default.aspx');">Bookmark</a> but to no avail.

     I also tried

    Dim bookScript As String = ""
    bookScript = "function CreateBookmarkLink(sTitle, sUrl) {"
    bookScript = bookScript & "if (window.sidebar) {window.sidebar.addPanel(sTitle, sUrl,'');}"
    bookScript = bookScript & "else if( window.external ) {window.external.AddFavorite(sUrl, sTitle);}"
    bookScript = bookScript & "else if(window.opera && window.print) {return true;}}"
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "BookScript", bookScript, True)

    and  

    <asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="CreateBookmarkLink()">LinkButton</asp:LinkButton> 

     And I tried the above, only using RegisterClientScriptBlock.  Nothing works.

    Diane 

    Sunday, April 1, 2007 2:07 PM

Answers

  • User-1844137581 posted

    Please try this,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    <o:p> </o:p>

    <asp:linkbutton ID="lbBookmark" runat="server" OnClientClick="CreateBookmarkLink('Write A Prisoner')">LinkButton</asp:linkbutton><o:p></o:p>

    <o:p> </o:p>

    and

    <o:p> </o:p>

         Dim sUrl = window.location.href;"<o:p></o:p>

    As String = ""<o:p></o:p>

            bookScript = "function CreateBookmarkLink(sTitle) { sUrl = window.location.href;"<o:p></o:p>

            bookScript = bookScript & "if (window.sidebar) {window.sidebar.addPanel(sTitle, sUrl,'');}"<o:p></o:p>

            bookScript = bookScript & "else if( window.external ) {window.external.AddFavorite(sUrl, sTitle);}"<o:p></o:p>

            bookScript = bookScript & "else if(window.opera && window.print) {return true;}}"<o:p></o:p>

            Page.ClientScript.RegisterStartupScript(Me.GetType(), "BookScript", bookScript, True)<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    The changes I made is sUrl = window.location.href;" <o:p></o:p>

    And reduced the number of parameter passed to the function to one.<o:p></o:p>

    <o:p> </o:p>

    If you want to pass variable dynamically, use string expressoins like

     

    <o:p> </o:p>

    <o:p></o:p>

    bookScript = "function CreateBookmarkLink(" & Request.ServerVariables("XXXXXX")  

    Regards<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 1, 2007 2:43 PM

All replies

  • User-1844137581 posted

    Please try this,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    <o:p> </o:p>

    <asp:linkbutton ID="lbBookmark" runat="server" OnClientClick="CreateBookmarkLink('Write A Prisoner')">LinkButton</asp:linkbutton><o:p></o:p>

    <o:p> </o:p>

    and

    <o:p> </o:p>

         Dim sUrl = window.location.href;"<o:p></o:p>

    As String = ""<o:p></o:p>

            bookScript = "function CreateBookmarkLink(sTitle) { sUrl = window.location.href;"<o:p></o:p>

            bookScript = bookScript & "if (window.sidebar) {window.sidebar.addPanel(sTitle, sUrl,'');}"<o:p></o:p>

            bookScript = bookScript & "else if( window.external ) {window.external.AddFavorite(sUrl, sTitle);}"<o:p></o:p>

            bookScript = bookScript & "else if(window.opera && window.print) {return true;}}"<o:p></o:p>

            Page.ClientScript.RegisterStartupScript(Me.GetType(), "BookScript", bookScript, True)<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    The changes I made is sUrl = window.location.href;" <o:p></o:p>

    And reduced the number of parameter passed to the function to one.<o:p></o:p>

    <o:p> </o:p>

    If you want to pass variable dynamically, use string expressoins like

     

    <o:p> </o:p>

    <o:p></o:p>

    bookScript = "function CreateBookmarkLink(" & Request.ServerVariables("XXXXXX")  

    Regards<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 1, 2007 2:43 PM
  • User50862095 posted

    This works, thank you!  I'll have to play with it to get the page name in there.  I was wondering though, why have the bookmark open in page as opposed to a page?

    Diane 

    Sunday, April 1, 2007 4:15 PM