Can a bookmarklet do this?

D

Danny

I have 4 separate websites, each with their own development address

I have a bookmarklet that replaces the first part of the URL with the
development page, but keeps the path and file name, which allows me to
jump back and forth between development and live without having to
retype anything.

I would like to create a bookmarklet that contains code for all 4
sites and their respective development pages.

I would like to create 4 scripts like the one below, each containing a
different site name, but combine it into the same bookmarklet.

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


Any suggestions?

I've tried to separate the code with a semicolon, but it did not work.

Thanks
 
D

Danny

Danny said the following on 8/7/2007 3:07 PM:



Your code and the premise seem somewhat vaguely familiar to me.


OK, then you use the last one I wrote you and expand it.



javascript:
a=location.href;
b=document.domain;
j="www.live1.com";
k="alt.live1.com";
l="www.live2.com";
m="alt.live2.com";
n="www.live3.com";
p="alt.live3.com";
q="www.live4.com";
r="alt.live4.com";
switch(k){
case j:s=k;break;
case k:s=j;break;
case l:s=m;break;
case m:s=l;break;
case n:s=p;break;
case p:s=n;break;
case q:s=r;break;
case r:s=q;break;};

a=a.replace(b,s);
location.href=a;

Edit the domains to match what you need remembering:
j and k will replace one another.
l and m will replace one another.
n and p will replace one another.
q and r will replace one another.
Remove all the line breaks so that it is all on one line.
Save it as a bookmarklet.
Test it and come back.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

javascript:a=location.href;b=document.domain;j="www.
43site.com";k="43site.dev.43site.com";l="www.46site.com";m="46site.dev.
46site.com";n="www.50site.com";p="50site.dev.50site.com";q="www.
54site.com";r="54site.dev.54site.com";switch(k){case j:s=k;break;case
k:s=j;break;case l:s=m;break;case m:s=l;break;case n:s=p;break;case
p:s=n;break;case q:s=r;break;case
r:s=q;break;};a=a.replace(b,s);location.href=a;

Above is what I applied to a bookmarklet, except it was all on one
line and breaks following "case." It only refreshed the page.

Thanks.
 
T

Thomas 'PointedEars' Lahn

Danny said:
I have 4 separate websites, each with their own development address

I have a bookmarklet that replaces the first part of the URL with the
development page, but keeps the path and file name, which allows me to
jump back and forth between development and live without having to
retype anything.

I would like to create a bookmarklet that contains code for all 4
sites and their respective development pages.

I would like to create 4 scripts like the one below, each containing a
different site name, but combine it into the same bookmarklet.

You should consider using a mapping object so that only one bookmarklet
would be required.
javascript:k=location.href;m=document.domain;n="www.thisisatest.com";
p="thisisatest.dev.thisisatest.com";if(document.domain==n)
{k=k.replace(m,p);}else{k=k.replace(m,n)}location.href=k;

Don't you know that `javascript:' is deprecated? ;-) (SCNR)

The cause of your problem is probably that you access `document.domain'.
That property has a distinct purpose. It does *not* return the domain part
of the URI of the displayed resource, but instead a string literal
containing a domain name can be assigned to it to work around the Same
Origin Policy. The default value of that property is the empty string.

You are looking for window.location.domain instead. There is no standards
compliant alternative that is accessible as affective as the former -- yet.

But your script code looks overly complicated.
Any suggestions?

I've tried to separate the code with a semicolon, but it did not work.

Not understood.


PointedEars
 
E

Evertjan.

Danny wrote on 07 aug 2007 in comp.lang.javascript:
I have 4 separate websites, each with their own development address

I have a bookmarklet that replaces the first part of the URL with the
development page, but keeps the path and file name, which allows me to
jump back and forth between development and live without having to
retype anything.

I would like to create a bookmarklet that contains code for all 4
sites and their respective development pages.

I would like to create 4 scripts like the one below, each containing a
different site name, but combine it into the same bookmarklet.

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

I have this favelet,
changing the local file on the HD for the real web thing:

[InternetShortcut]
URL=javascript:location.href=location.href.replace(/file:...C:.homepages.
([^\/]+)/,"http://$1.org");void 0

[All my homepages end in .org, do not have www.]

=====================================

C:\homepages\myDomain\index.html

IE will change this to:

file:///C/homepages/myDomain/index.html

which is exchanged by the favelet with

http://myDomain.org/index.html

=====================================

C:\homepages\myOtherDomain\myDir\blah.html

IE will change this to:

file:///C/homepages/myOtherDomain/myDir/blah.html

which is exchanged by the favelet with

http://myOtherDomain.org/myDir/blah.html
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top