简体   繁体   English

如何在Windows Phone 7浏览器中通过javascript打开新窗口或选项卡

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

Is it possible to open a new window or tab via javascript in Windows Phone 7 browser? 是否可以通过Windows Phone 7浏览器中的javascript打开新窗口或选项卡?

window.open does not appear to be supported nor does target='_blank' . window.open似乎不受支持,也不是target='_blank'

Am I missing something here? 我在这里错过了什么吗? This basic feature works just fine on iphone and android. 这个基本功能在iphone和android上运行得很好。 Any ideas on how I can get this working in Windows Phone 7? 有关如何在Windows Phone 7中使用此功能的任何想法?

On Windows Phone 7 this is not possible programmatically. 在Windows Phone 7上,这不可能以编程方式进行。 It's all in the users hand. 这一切都在用户手中。

To cite a Microsoft employee : 引用Microsoft员工

"A user can open a link in a new Tab by tapping and holding the link to get the context menu but an anchor or scripts request to target a new window is ignored. “用户可以通过点击并按住链接来打开新标签中的链接以获取上下文菜单,但忽略了定位新窗口的锚点或脚本请求。

There are several reasons for this: 有几个原因:

  • Cross-window communications are not supported. 不支持跨窗口通信。
  • Windows Phone only has one instance of the browser so new "windows" have to be opened as Tab's. Windows Phone只有一个浏览器实例,因此必须以Tab键的形式打开新的“windows”。
  • The browser experience is full screen so the user has no good visual cue that they have moved to a new Tab unless they explicity request it. 浏览器体验是全屏的,因此用户没有良好的视觉提示他们已经移动到新的Tab,除非他们明确要求它。
  • Navigating "back" in a new Tab exits the browser which would be confusing to the user if they did not know a new Tab was created." 在新的选项卡中导航“返回”会退出浏览器,如果用户不知道创建了新的选项卡,则会让用户感到困惑。“

If you are trying to add this feature for in-ap browser control, I can suggest you one way. 如果您尝试为in-ap浏览器控件添加此功能,我可以建议您使用一种方法。

You have to inject a java-script on every webpage the browser control is able to load the page successfully. 您必须在浏览器控件能够成功加载页面的每个网页上注入一个java脚本。 In the java-script use window.extern.notify to invoke the ScriptNotify function in your code behind. 在java脚本中使用window.extern.notify来调用代码后面的ScriptNotify函数。 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');};"; 要注入的JS代码可能类似于此String NEW_TAB_FUNCTION = "window.open = function(__msg){window.external.notify('addnewtab');};";

Which can be injected using browser.InvokeScript("eval", NEW_TAB_FUNCTION); 可以使用browser.InvokeScript("eval", NEW_TAB_FUNCTION);注入browser.InvokeScript("eval", NEW_TAB_FUNCTION);

In ScriptNotify check for addnewtab (keep IsScriptEnabled = True ) 在ScriptNotify中检查addnewtab (保持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. 请注意,我已经使用一个函数覆盖了JS中的window.open函数,该函数每次都会在新网页上注入,以便获得用户输入的通知。

Also note this works only for WebBrowser Control and not external browser. 另请注意,这仅适用于WebBrowser Control,而不适用于外部浏览器。

My workaround this issue is simple: 我的解决方法这个问题很简单:

window.open

returns null if failed, so in that case I open it in the same window: 如果失败则返回null,所以在这种情况下我在同一个窗口中打开它:

var win = window.open(href, '_blank');
    if(!win || win==null){
        window.location.href = href;
    }else{
        win.focus();     
    }

which is a good practice to have a fallback anyway... 无论如何,这是一个很好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何打开新的浏览器窗口(不是选项卡),然后使用jQuery / Javascript调整其大小 - How to open new browser window (not tab) and then resize it using jQuery / Javascript JavaScript在新标签页中打开,而不是Chrome浏览器中的窗口 - JavaScript open in a new tab, not window in Chrome browser 如何通过JavaScript在新的浏览器窗口中仅打开外部链接? - How to open only external links in a new browser window via JavaScript? 如何强制打开JavaScript的新标签/窗口? - how to force open new tab / window for javascript? 如何从 javascript 打开新窗口/标签 - How to open a new window/tab from javascript 使用JavaScript在Google Chrome浏览器的打开新标签页窗口中出现的问题 - Issue in open new tab window for Google Chrome Browser using javascript Javascript打开一个禁用地址栏的新浏览器窗口(不是选项卡) - Javascript open a new browser window (not tab) with address bar disabled 如何强制重定向到手机浏览器的新窗口或标签页? - How to force the redirection to a new window or tab in a mobile phone browser? 如何在 window.open window - Javascript 中打开新选项卡 - How to open a new tab within window.open window - Javascript 如何使用JavaScript打开新的浏览器窗口? - How to open new browser window using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM