Forum Moderators: open

Message Too Old, No Replies

Open Multiple Tabs By inputting the values

Open Multiple Tabs in IE

         

ckrisasa

11:09 am on Nov 4, 2010 (gmt 0)

10+ Year Member



Hi There,

Below is the code that I obtained from MSDN to open Multiple URLs in tabs of an IE Window.

var navOpenInBackgroundTab = 0x1000;
var oIE = new ActiveXObject("InternetExplorer.Application");

oIE.Navigate2("http://dssapps.com/runbook/QDetail.asp?ServerName=<Server Name>");
oIE.Navigate2("http://dssapps.com/runbook/QDetail.asp?ServerName=<Server Name>", navOpenInBackgroundTab);

oIE.Visible = true;


The above script helps me open multiple servers information in multiple tabs in the same IE Window.

I'm happy that it works. But I need to manually change or update the field <Server Name> every time in the URLs I mention above.

Is there any way that I can paste the list of servers in a notepad and then <Server Name> is pulled automatically from the notepad into the field in the URL?

That saves a lot of time for me.

B.T.W its a Java Script file works Wscript.exe

Thanks in Advance!
Arun

astupidname

8:12 am on Nov 5, 2010 (gmt 0)

10+ Year Member



Hi ckrisasa and welcome to webmasterworld!
The below piece of JScript (not actually Javascript) will do what you want, just create a text file with the server names each on a seperate line and no blank lines, then update the serverNamesFilePath variable in the getServers() function. Note I have not addressed whether serverNames[j] may need escaping yet or not, that may be dependant upon how you use.

//if run from a html page, path must be full system path to the file, such as 'C:/myfolder/myfile.txt'
function getFileText(path, asArray) {
//scripting the FileSystemObject
//http://msdn.microsoft.com/en-us/library/d6dw7aeh(v=VS.85).aspx
var fso = new ActiveXObject('Scripting.FileSystemObject'),
tf = fso.OpenTextFile(path, 1), //the '1' means ForReading,
//2 would be ForWriting,
//8 would be ForAppending, consult: http://msdn.microsoft.com/en-us/library/czxefwt8(v=VS.85).aspx
s = tf.ReadAll();
return (asArray) ? s.split('\r\n') : s;
}

function getServers() {
var j,
oIE = new ActiveXObject("InternetExplorer.Application"),
basePath = 'http://dssapps.com/runbook/QDetail.asp?ServerName=',
//update serverNamesFilePath to the location of your server names text file on your computer:
serverNamesFilePath = 'C:/testing/IEopenMultiTabs/serverNames.txt',
serverNames = getFileText(serverNamesFilePath, true),
len = serverNames.length;
for (j = 0; j < len; j++) {
if (j > 0) {
oIE.Navigate2(basePath + serverNames[j], 4096); //4096 equivalent of navOpenInBackgroundTab or 0x1000
} else {
oIE.Navigate2(basePath + serverNames[j]);
}
}
oIE.Visible = true;
}

getServers();

If anybody's wondering, how to post formatted code on webmasterworld [webmasterworld.com]
Do not copy formatted code on webmasterworld from IE, use other browser such as Firefox.

ckrisasa

7:48 am on Nov 8, 2010 (gmt 0)

10+ Year Member



Thanks very much and appreciate the speedy reply..! :D

Fact is that, I'm not great at coding..! But I can understand if I go through it couple of times..!

Actually.. You gave what I want. I'm happy. But I have to blame myself for not posting my question completely.. :(

I missed another thing there.. There is another type of URL where the ServerName value comes in the middle.

Here is the example URL and it's lengthy. Apologize if it's confusing!

http://wsuapps.com/vitu/index.pl?module=vms&SortBy=BRS_ID&SortRev=1&SortNum=1&SearchValue=<Server Name>&SearchField=ServerName&xlout=&loc=&env=&status=%21All&seng=&ieng=&ops=&tier=

Is there a way we can pull of the above trick with this sort of URL..?!

Pardon me if I'm trying to hammer on something that doesn't exist.

Kindly Reply!

Regards,
Ckrisasa

ckrisasa

2:39 pm on Nov 8, 2010 (gmt 0)

10+ Year Member



I figured it out..! As I told.. I went through the code couple of times and I noticed "basePath". I created two basePaths and defined it in the "for" loop.

Like:

(basePath1 + serverNames[j] + basePath2)

Thanks once again for the above code..! It might be a simple code for you.. But it matters a lot for me! :D

I'll keep posting if any help needed on this further..

Thanks Once Again AStupidName!