在新窗口中打开网页的工作方法?

时间:2012-06-15 02:59:44

标签: javascript extjs sencha-touch-2 new-window

我一直在尝试用sencha touch编写代码,它有一个按钮,当我点击它时,它应该在新窗口中打开一个弹出的网页。

  1. Window.open() - 我无法使用此方法,因为它无法正常工作 在手机中。虽然我意识到这是打开新手机的最简单方法 浏览器窗口。

  2. document.location.href = url - 此方法以相同的方式打开URL 页面,但我希望它在弹出窗口的新窗口中打开。

  3. 当用户点击按钮时,有没有其他方法可以在新窗口中打开页面,下面是我的代码

    Ext.application({
        name: 'Opening new page',
    
        launch: function() {
            Ext.create("Ext.tab.Panel", {
                fullscreen: false,
                items: [
                    {
                        xtype: 'button',
                        text: 'click to open google',
                        ui: 'confirm',
                        handler: function() {
                            document.location.href=("http://www.google.com/");
                        }
                    }
                ]
            });
        }
    });
    

5 个答案:

答案 0 :(得分:0)

请尝试以下代码:

handler: function() {
  var link = Ext.getDom('hidden_link');
  link.href = 'http://www.google.com'/;
  var clickevent = document.createEvent('Event');
  clickevent.initEvent('click', true, false);
  link.dispatchEvent(clickevent);
}

答案 1 :(得分:0)

我不知道在Ext.js中究竟该怎么做,但我基本上和@ bunlong-van一样思考。创建一个定位新窗口的锚标记,将其添加到页面,然后单击它。

这是如何在jQuery中完成的:

  $('button').bind('click',function(e){
      var $me = $(this);
      e.preventDefault();
      e.stopPropagation();
      $('<a />')
        .attr('href', $me.data('href'))
        .attr('target', '_blank')
        .css({display:'none'})
        .appendTo($('body'))
        .get(0).click();
  });

完整示例:http://jsbin.com/adakur/edit

答案 2 :(得分:0)

嘿@coding你可以这是一个Overlay是一个类型的弹出窗口,试试这个到处理程序事件,

var overlay = new Ext.Panel({
    floating : true,
    modal : true,
    centered : true,
    width : 500,
    height : 500,
    styleHtmlContent : true,
    html: '<div><iframe style="width:100%;height:100%;" src="http://www.sencha.com/products/touch">Your device does not support iframes.</iframe></div>',
}).show('pop', true)

请用你的大脑,我不能做你的功课。我希望这有帮助。 :) Ciao enter image description here

答案 3 :(得分:0)

在您的处理程序中使用 window.open() ,如下所述:

handler: function() { 
    window.open("http://www.google.com/", "_blank"); 
}

答案 4 :(得分:-1)

在工作页面中创建一个弹出窗口(一个简单的窗口)并使其可见性为false ..当您单击该按钮时,将其可见性更改为true并将焦点置于其中。 你也可以在弹出窗口中打开任何东西..

或者你可以使用这个jQuery代码

$(document).ready(function() { tb_show(title, "testpage.aspx?id=" + url + "&TB_iframe=true&width=700&height=600", null); });

在这里你可以传递你想要的参数。这将作为一个新的弹出窗口打开。