How to open a new window or tab via javascript in windows phone 7 browser

前端 未结 3 1946
小鲜肉
小鲜肉 2020-12-06 01:48

Is it possible to open a new window or tab via javascript in Windows Phone 7 browser?

window.open does not appear to be suppor

3条回答
  •  Happy的楠姐
    2020-12-06 02:33

    If you are trying to add this feature for in-ap browser control, I can suggest you one way.

    You have to inject a java-script on every webpage the browser control is able to load the page successfully. In the java-script use window.extern.notify to invoke the ScriptNotify function in your code behind. On the detection of the appropriate message create a new instance of browser control and add it to an array or list. Thereby you can emulate the new tab feature for in-app browser control.

    the JS code to be injected may be like this String NEW_TAB_FUNCTION = "window.open = function(__msg){window.external.notify('addnewtab');};";

    Which can be injected using browser.InvokeScript("eval", NEW_TAB_FUNCTION);

    In ScriptNotify check for addnewtab (keep IsScriptEnabled = True)

        void WebBrowser_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (e.Value == "addnewtab")
            {   
                //do work here
            }
        }
    

    Note that I have overridden the window.open function in the JS with a function which will be injected every time on a new webpage in order to get notified of user input.

    Also note this works only for WebBrowser Control and not external browser.

提交回复
热议问题