Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7641225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:52:10+00:00 2026-05-31T08:52:10+00:00

i successfully added a contextmenu to my webbrowser with this javascript code: public void

  • 0

i successfully added a contextmenu to my webbrowser with this javascript code:

public void AttachContextMenu()
        {
            try
            {
                if ((App.Current as App).Browser.IsScriptEnabled)
                {
                    (App.Current as App).Browser.InvokeScript("execScript", "function FindParentLink(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'a') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentLink(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction FindParentImage(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'img') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentImage(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction HandleContextMenu() \r\n{\r\n\tvar linkItem = FindParentLink(event.srcElement);\r\n    var imageItem = FindParentImage(event.srcElement);\r\n    var notifyOutput = '';\r\n    if (linkItem != null) if (linkItem.href != null) notifyOutput += linkItem.href;\r\n    if (imageItem != null) if (imageItem.src != null) notifyOutput += imageItem.src;\r\n    if (notifyOutput != '')\r\n        window.external.notify(notifyOutput);\r\n    else\r\n\t\twindow.external.notify('NOTLINKIMG');\r\n}");
                    (App.Current as App).Browser.InvokeScript("execScript", "document.oncontextmenu = HandleContextMenu;");
                }
            }
            catch
            {
            }
        }

this method is used everytime the browser navigated.
So, the scriptnotify code, which will be used when the user holds a link :

 if (e.Value.ToString() != null && IsValidUri(e.Value.ToString()))
            {
                ContextMenu cm = new ContextMenu();
                MenuItem menuItem0 = new MenuItem() { Header = "X", Tag = e.Value };
                menuItem0.Click += new RoutedEventHandler(X_Click);
                MenuItem menuItem1 = new MenuItem() { Header = "Y", Tag = e.Value };
                menuItem1.Click += new RoutedEventHandler(Y_Click);
                MenuItem menuItem2 = new MenuItem() { Header = "Z", Tag = e.Value };
                menuItem2.Click += new RoutedEventHandler(Z_Click);

                    cm.Items.Add(menuItem0);
                    cm.Items.Add(menuItem1);
                    cm.Items.Add(menuItem2);


                ContextMenuService.SetContextMenu(Browser, cm);
                cm.IsZoomEnabled = false;
                cm.VerticalOffset = mouseClickPosition.Y;
                cm.IsOpen = true;
            }

so far, i hope i made everything right.
now, it randomly works. nearly 50% of tries cause a error, Visual studio navigates to a blue-white frame named “No source available” and throws a NullReferenceException.

Where should this be solved? already set a try-catch block around the hole 2 method, no change :/

hope you have some ideas

greets
roqstr

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:52:12+00:00Added an answer on May 31, 2026 at 8:52 am

    don’t got it working, but there’s a workaround:

    AttachContextMenu()

    -> holding a link will push the url to the scriptnotify method.

    build a custom contextmenu & everything is fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have successfully added input element into div, which looks like this : $(document).ready(function()
I've just followed this example from Wordpress and I have successfully added an extra
I'm attempting to use a ContextMenu. I've successfully done this for a simple ListActivity
I have successfully added a dynamic library to a program, but when I try
I have successfully added admob ads to my android app and can view test
I have successfully added other .dll files to other C# project this way: Right
I have successfully added metadata to a jpg created within the app and saved
I've successfully added a French localisation to my app. In XCode 4, it was
How do you reposition an element within a maplayer? I've successfully added a UIElement
I have a png icon, it's added successfully in my project, but not included

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.