views:

4079

answers:

4

Hello, I am using ExtJS version 2. I am clicking a button to add new tab to a TabPanel. The new tab function looks like this:

function addTab(tabTitle, targetUrl){
        tabPanel.add({
        title: tabTitle,
        iconCls: 'tabs',
        closable:true
    }).show();
    }

I would like to know if it's possible to get the targetUrl and display it in new tab. If i set html: targetUrl, my tab content would obviously be just a text with my URL. If I set up the autoLoad: {url: targetUrl} it works but it is reading the file contents as if they were texts or scripts.. The problem is that I would need to open images and I just get their source with autoLoad, not the actual display of the image. I just want my new tab to act like a new pop-up window with a default link.

Can anybody help ?

Thanks.

A: 

if the URL is an HTML snippit, not a full page, you'll need to make an AJAX call to fetch the contents and update the tab. If the page is a full page, including <html> and <body> tags, then you should make the tab contain an iFrame with "src=\""+url+"\""

Josh
I thought of an iframe but how can I set its width and height based on my center panel size ?
Manny Calavera
Try width="100%" height="100%" -- if that doesn't work add an onresize handler to the panel which resizes the iFrame.
Josh
+1  A: 

In Extjs you can load any panel with the contents of a url. You can do it like this

var panel = new Ext.Panel({
    title: 'Your Tile',
    closable: true,
    iconCls: 'tabs',
    autoLoad: {
        url: targetUrl
    }
});
tabPanel.add(panel);
tabPanel.doLayout();
tabPanel.setActiveTab(panel);

You can find more details in the Extjs API documentation.

Arun P Johny
Please, execute the code you posted and tell me if you can display an image with its path as targetUrl. Because I can't. I get characters like this: "�����I�+�Lj���%��xjE9" because you can't just send an image through GET or POST..
Manny Calavera
Right. The URL must return an image tag. If it returns an image, you need to have an onLoad handler which updates the content to be "<img src=\""+url+"\">"
Josh
A: 

Why you want to sent the image through the response, you can simply specify the url of the image as the html of the panel.

var panel = new Ext.Panel({
    title: 'Your Tile',
    closable: true,
    iconCls: 'tabs',
    url:'<img src="http://yourdomain.com/images/image.gif" />'
});
Arun P Johny
Because it's not only images that I have to send. I have to send PDF files, html files, any kind.
Manny Calavera
A: 

Nevermind, I have used the ManagedIframe script witch happens to do exactly what I requested. Thanks anyway.

Manny Calavera
Yeah that script basically does what I recommended. I just wasn't sure if that's what you were looking for or not.
Josh