Internet Explorer Browser Extension: Switching from Live to Development and back again with a browse

D

Danny

Hello:

I would like to develop a browser extension, or whatever such a thing
is classified as, that would allow a user of IE6, and possibly IE7,
to
switch between a live and development page.

I'm sure the individuals reading this are familiar with what I'm
referring to; however, I'll provide an example.

I'm currently viewing a page, which is http://www.project.com/project-five.jsp,
and I would like to view the development version of that page, which
is http://project.dev.project.com/project -five.jsp--I would like to
switch back and forth
with one button, which of course would be "attached" to whatever
scripting language
accommodates such an action. I've had limited success with the "href"
and window.location
(or location.window) function in JS, but nothing that would allow me
to do the aforementioned.

I'm thinking that the code for this process would be executed by a
button
on the browser toolbar, which would be fed from the registry, which
is
probably the only part of this procedure I know how to perform.

I'm aware of Server Switcher, a browser add-on for FireFox, but I
would need to have this component for IE 6 and IE 7, and I would need
to develop this myself

I 'd like to know what tools I need for this type of project, and
what
type of programming I'm looking at; type of environment am I looking
at working in?

I've looked at some javascript and I've been given some code, but none
that I can seem to make work.

If this is a simple coding procedure that someone is familiar with
and
it could be provided here, it would be greatly appreciated.

If you believe that this message would be better suited posted to
another discussion group, please advise.


Thank you in advance for your time and attention.
---------------------------------------------------------------------------­-----
Daniel R. Young
 
R

Randy Webb

Danny said the following on 6/12/2007 11:12 AM:
Hello:

I would like to develop a browser extension, or whatever such a thing
is classified as, that would allow a user of IE6, and possibly IE7,
to switch between a live and development page.

I do that daily with IE7 and it is trivial. I open the development page
in on tab, the live page in another and switch between tabs. Why do I
need an add-on to allow me to do that? With IE6, there are already
add-ons that allow you to have tabbed browsing. Prior to the tabs, I
would simply open two browser windows and open two pages. No need for a
plugin/extension.
 
D

Danny

Danny said the following on 6/12/2007 11:12 AM:



I do that daily with IE7 and it is trivial. I open the development page
in on tab, the live page in another and switch between tabs. Why do I
need an add-on to allow me to do that? With IE6, there are already
add-ons that allow you to have tabbed browsing. Prior to the tabs, I
would simply open two browser windows and open two pages. No need for a
plugin/extension.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

If it were that simple, I wouldn't have posted such a question. An add-
on such as this is available in FireFox, which supports tabbed
browsing. This add-on would concatenate the dev. URL, keep the path
and file name, but replace the domain. Get it? If you don't
collaborate with end-users, I doubt you'd understand why there's a
need for such an add-on,

Thanks anyway.
 
R

Randy Webb

Danny said the following on 6/12/2007 5:43 PM:
If it were that simple,

It *is* that simple and I even told you how.
I wouldn't have posted such a question.

Just because you ask a question doesn't mean the solution isn't simple.
An add-on such as this is available in FireFox,

Then someone wasted a lot of time on making something for Firefox that
is trivial to do without a plug-in/add on.
which supports tabbed browsing. This add-on would concatenate the dev. URL,
keep the path and file name, but replace the domain.

I can do that with a bookmark, add it to the toolbar. Why do I need an
addon?

I got it the first time I answered you. You are the one trying to make
it more difficult than it is.
If you don't collaborate with end-users, I doubt you'd understand
why there's a need for such an add-on,

I "collaborate" with my end-users on a daily basis. Most times I
"collaborate" with them more than I wanted to.

x=document.location;
k = x.href.substring(8);
//change the 8 to pick up the parts you want to keep.
y = x.href.substring(0,8);
//change the 8 to pick up the live domain that you want to discard.
if(y="liveURLHere")
{x.href="devURLHere" + filePath}
else
{x.href="liveURLHere" + filePath}

Substitute the devURL and the liveURL, remove the comments, put it all
on one line, save it as a bookmarklet, add it to the IE toolbar.

Now, since you "Get it" and you seem to think I don't. Can you please
explain to me, and anybody else reading, why I need to install an addon
(to any browser) to allow me to do what the above bookmarklet will do?
 
D

Danny

Danny said the following on 6/12/2007 5:43 PM:



It *is* that simple and I even told you how.


Just because you ask a question doesn't mean the solution isn't simple.


Then someone wasted a lot of time on making something for Firefox that
is trivial to do without a plug-in/add on.


I can do that with a bookmark, add it to the toolbar. Why do I need an
addon?


I got it the first time I answered you. You are the one trying to make
it more difficult than it is.


I "collaborate" with my end-users on a daily basis. Most times I
"collaborate" with them more than I wanted to.

x=document.location;
k = x.href.substring(8);
//change the 8 to pick up the parts you want to keep.
y = x.href.substring(0,8);
//change the 8 to pick up the live domain that you want to discard.
if(y="liveURLHere")
{x.href="devURLHere" + filePath}
else
{x.href="liveURLHere" + filePath}

Substitute the devURL and the liveURL, remove the comments, put it all
on one line, save it as a bookmarklet, add it to the IE toolbar.

Now, since you "Get it" and you seem to think I don't. Can you please
explain to me, and anybody else reading, why I need to install an addon
(to any browser) to allow me to do what the above bookmarklet will do?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/


OK, I've used the wrong terminology and that's why you're viewing this
as superfluous-I at least that's why I've interpreted this as. Instead
of add-on, I should have said IE Toolbar button, but not a favorite.

I did as you suggested, with the code pasted above, and the script
host returned an error: "'window is undefined'."

It's possible that I didn't describe this requirement of the script. I
would need the script to understand that the path and filename will
not be the same in all instances. Sometimes you'd visit
http://www.live.com/file-path-name.jsp and want to switch to it's
respective development page, but other instances the file and path
name would be http://www.live.com/ff2-pp2-nn2.jsp, and I would need
the script to recognize the path and file name, capture it, (or
whatever function JS could provide in such a situation), and replace
the live domain (http://www.live.com) with the development domain
(http://live.dev.live.com).
 
R

Randy Webb

Danny said the following on 6/13/2007 2:04 PM:
OK, I've used the wrong terminology and that's why you're viewing this
as superfluous-I at least that's why I've interpreted this as. Instead
of add-on, I should have said IE Toolbar button, but not a favorite.

Why though? Why won't a favorite work if it can be coded to work?
I did as you suggested, with the code pasted above, and the script
host returned an error: "'window is undefined'."

That is an odd error as nothing in the script tried to access a "window".
It's possible that I didn't describe this requirement of the script. I
would need the script to understand that the path and filename will
not be the same in all instances.

I understood that part :)
Sometimes you'd visit http://www.live.com/file-path-name.jsp and
want to switch to it's respective development page, but other
instances the file and path name would be http://www.live.com/ff2-pp2-nn2.jsp,
and I would need the script to recognize the path and file name,
capture it, (or whatever function JS could provide in such a
situation), and replace the live domain (http://www.live.com)
with the development domain (http://live.dev.live.com).

If all you want to change is the domain of the page, no sub folders,
then you simply read the document.domain property which gives you the
www.live.com (or live.dev.live.com part) of the URL. You check that to
see which it is - live or dev - and replace it with the other, then set
location.href of the current page. The snippet I posted before had a
flaw where it assumed (incorrectly) that the domain names would be the
same length when that isn't always true.

//set a variable to the location.href property
k=location.href;
//read the domain
m=document.domain;
//define a variable for each domain name
n="www.live.com";
p="live.dev.live.com";
//check the domain to see which it is and branch accordingly
if(document.domain == n){
//replace the domain name in k with the new domain name
k=k.replace(m,p);
}else{
//replace the domain name in k with the domain name of p
k=k.replace(m,n)
}
//k now equals a string that represents the new URL so
//set the location.href property to k
location.href = k;

When you strip out the comments, remove the linebreaks, and add the
javascript: protocol to it, you end up with this:

javascript:k=location.href;m=document.domain;n="www.live.com";p="live.dev.live.com";if(document.domain==n){k=k.replace(m,p);}else{k=k.replace(m,n)}location.href=k;

Save it as a bookmark.
Edit the n and p variables to match your respective domain names.

I don't have two live servers that I can tinker with right now to
thoroughly test it with but testing with variables instead of
location.href and document.domain I can't get it to fail in IE7. Try it
and if it still throws an error then let me know what the error was and
I will look into it some more. Whether you use a bookmark written in
javascript or any other language the process is the same.
 
D

Danny

Danny said the following on 6/13/2007 2:04 PM:







Why though? Why won't a favorite work if it can be coded to work?


That is an odd error as nothing in the script tried to access a "window".


I understood that part :)


If all you want to change is the domain of the page, no sub folders,
then you simply read the document.domain property which gives you thewww.live.com(or live.dev.live.com part) of the URL. You check that to
see which it is - live or dev - and replace it with the other, then set
location.href of the current page. The snippet I posted before had a
flaw where it assumed (incorrectly) that the domain names would be the
same length when that isn't always true.

//set a variable to the location.href property
k=location.href;
//read the domain
m=document.domain;
//define a variable for each domain name
n="www.live.com";
p="live.dev.live.com";
//check the domain to see which it is and branch accordingly
if(document.domain == n){
//replace the domain name in k with the new domain name
k=k.replace(m,p);}else{

//replace the domain name in k with the domain name of p
k=k.replace(m,n)}

//k now equals a string that represents the new URL so
//set the location.href property to k
location.href = k;

When you strip out the comments, remove the linebreaks, and add the
javascript: protocol to it, you end up with this:

javascript:k=location.href;m=document.domain;n="www.live.com";p="live.dev.live.com";if(document.domain==n){k=k.replace(m,p);}else{k=k.r­eplace(m,n)}location.href=k;

Save it as a bookmark.
Edit the n and p variables to match your respective domain names.

I don't have two live servers that I can tinker with right now to
thoroughly test it with but testing with variables instead of
location.href and document.domain I can't get it to fail in IE7. Try it
and if it still throws an error then let me know what the error was and
I will look into it some more. Whether you use a bookmark written in
javascript or any other language the process is the same.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/- Hide quoted text -

- Show quoted text -

The message I'm receiving is 'location is undefined.' I've saved the
file as a .js file, and placed it in Internet Explorer's Favorites
folder. Should this be an html file?

Thanks.
 
R

Randy Webb

Danny said the following on 6/14/2007 10:25 AM:
The message I'm receiving is 'location is undefined.' I've saved the
file as a .js file, and placed it in Internet Explorer's Favorites
folder. Should this be an html file?

No, the above code, that begins with javascript: is the URL of a favorites.
 
D

Danny

Danny said the following on 6/25/2007 2:25 PM:






Welcome, and just think, it didn't take an add-on or plug-in :)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/- Hide quoted text -

- Show quoted text -

True, it didn't. Quick question: What would be needed to allow the
script to accommodate another domain? For instance
javascript:k=location.href;m=document.domain;n="www.live.com";p="live.dev.live.com";if(document.domain==n)
{k=k.replace(m,p);}else{k=k.r­­­eplace(m,n)}location.href=k; and then
I'd like to add live25 to the domain list, and of course
live25.dev.live.com.? Would it require an IF ELSE sequence, or
something totally different?

Thanks again.
 
D

Danny

Danny said the following on 6/25/2007 5:43 PM:







It would probably be simplest to use an if/else for readability but the
simplest way would be to use a ternary statement or two.

If the domain iswww.live.com, redirect to live.dev.live.com
If the domain is live.dev.live.com, redirect towww.live.com
If the domain iswww.live25.com, redirect to live25.dev.live.com
If the domain is live25.dev.live.com, redirect towww.live25.com

Is that right before I tinker with it?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/- Hide quoted text -

- Show quoted text -

Yes, that's correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top