473,666 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bookmarklet for random url

I've found examples of bookmarklets that select a URL from a page at
random, but I'd like one that generates part of the URL at random.

If you have a bunch of images that are named:
mydomain.com/images/abcd.jpg where abcd is can be any combination of 4
lowercase letters - is there a way of having the bookmarklet generate
the letters randomly when clicked?

I'm able to do it using AppleScript & Safari but would like it to work
from within Safari - which is missing the "Scripts" menu that most Apple
apps have :(

It looks as if bookmarklets are the only option, but I've only ever used
javascript to select randomly from existing arrays of images and don't
fancy typing in the names of a couple of thousand images...

TIA

--
Martin
Jul 20 '05 #1
5 1902
Lee
Martin said:

I've found examples of bookmarklets that select a URL from a page at
random, but I'd like one that generates part of the URL at random.

If you have a bunch of images that are named:
mydomain.com/images/abcd.jpg where abcd is can be any combination of 4
lowercase letters - is there a way of having the bookmarklet generate
the letters randomly when clicked?

I'm able to do it using AppleScript & Safari but would like it to work
from within Safari - which is missing the "Scripts" menu that most Apple
apps have :(

It looks as if bookmarklets are the only option, but I've only ever used
javascript to select randomly from existing arrays of images and don't
fancy typing in the names of a couple of thousand images...


The easy solution is to create a regular bookmark to a page containing:

<html>
<head>
<script type="text/javascript">
function r(){
return Math.floor(Math .random()*26)+" a".charCodeAt() ;
}
location.replac e("mydomain.c om/images/"
+String.fromCha rCode(r(),r(),r (),r())
+".jpg");
</script>
</head>
<body>
Oops, that image doesn't exist.
</body>
</html>

Jul 20 '05 #2
In article <br*********@dr n.newsguy.com>,
Lee <RE************ **@cox.net> wrote:
The easy solution is to create a regular bookmark to a page containing:


[snip]

Thanks for that Lee - funny how you get stuck thinking that the answer
lies in one direction (bookmarks) when there is a much simpler solution.

One more question :-)

If I wanted to include numbers as well as letters, do I need to state a
string first (0-9, a-z etc) and get the script to select from items 1-36
of the string or is there a shortcut?

Regards

--
Martin
Jul 20 '05 #3
Lee
Martin said:

In article <br*********@dr n.newsguy.com>,
Lee <RE************ **@cox.net> wrote:
The easy solution is to create a regular bookmark to a page containing:


[snip]

Thanks for that Lee - funny how you get stuck thinking that the answer
lies in one direction (bookmarks) when there is a much simpler solution.

One more question :-)

If I wanted to include numbers as well as letters, do I need to state a
string first (0-9, a-z etc) and get the script to select from items 1-36
of the string or is there a shortcut?


Nothing simpler comes to mind.

Jul 20 '05 #4
JRS: In article <br*********@dr n.newsguy.com>, seen in
news:comp.lang. javascript, Lee <RE************ **@cox.net> posted at Mon,
8 Dec 2003 09:28:29 :-
function r(){
return Math.floor(Math .random()*26)+" a".charCodeAt() ;
}
location.replac e("mydomain.c om/images/"
+String.fromCha rCode(r(),r(),r (),r())
+".jpg");

For amusement : the first generates a string of up to 4 alphanumerics,
and the second generates four-letter words. 1679616 = 36^4

with (Math) floor(random()* 1679616).toStri ng(36)

do { with (Math) x = floor(random()* 1679616).toStri ng(36) }
while (!/[a-z]{4}/.test(x))

In the first, subtract 36^3 from 36^4 and add 36^3 to the result of
floor, and there should always be 4 alphanumerics, with the first in
1..z.

This seems OK too :

S = ""
while (S.length<4)
S += "abcdefghijklmn opqrstuvwxyz".c harAt(Math.rand om()*26)
x = "mydomain.c om/images/"+S+".jpg"

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #5
In article <Gp************ **@merlyn.demon .co.uk>,
Dr John Stockton <sp**@merlyn.de mon.co.uk> wrote:
This seems OK too :

S = ""
while (S.length<4)
S += "abcdefghijklmn opqrstuvwxyz".c harAt(Math.rand om()*26)
x = "mydomain.c om/images/"+S+".jpg"


Thanks

I used this one - as it was the only one I could actually understand :(
- by adding 0 thru 9 to the string and multiplying by 36.

Regards

--
Martin
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1873
by: Kim Scarborough | last post by:
I found this bookmarklet that will go to a random link on the currently open page: javascript:void(location.href=document.links) Could this be changed to go to a random link from the bookmarks file in Mozilla-derived browsers? How would it be done? -- ---------------------------------------------------------------------------- Kim Scarborough http://www.unknown.nu/kim/
2
1364
by: Gaikokujin Kyofusho | last post by:
Hi, I am trying to find a wikipedia bookmarklet for Opera that would allow me to lookup something highlighted on a page. I could have sworn that the one i had worked until i had to reinstall opera (why would that make a difference? all the other bookmarklets continued to work). Any help would be thoroughly appreciated, perhaps someone out there has written such a bookmarklet or knows where to find one? Thank you, -Gaiko
1
1756
by: Robert Oschler | last post by:
In pre-Windows XP Internet Explorer, adding a bookmarklet for a user was really simple. All I add to do was create a link that executed addFavorite(). Internet Explorer under Windows XP won't allow that due to its new security measures. How can I make adding a bookmarklet convenient for my Windows XP IE users without having them to do surgery on their security preferences?
4
3562
by: gwtc | last post by:
Here is a google search site bookmarklet. This lets you search a certain website using google. What I want is the same thing, but to search a certain geocities site. When you use the current bookmarklet, the search takes you to site:www.geocities.com instead of the specific site you want to search. Can someone modify this for me, to search specific geocities sites? Thanks for your help and btw I'm using Mozilla Suite and Firefox. ...
1
5901
by: OtisUsenet | last post by:
Hi, I have a bookmarklet that works perfectly in Firefox, IE, Konqueror, and Opera, but in Safari 2.0.3 (417.9.2) it doesn't work. I enabled debugging and I can see "TypeError - Undefined value" reported in the Javascript console, but I'm not sure where the error is. The bookmarklet in question is here: javascript:if (parseInt(navigator.appVersion) >= 4) { if
25
2589
by: bweaverusenet | last post by:
Hi. I am trying to get some javascript to work in IE6, from the address line. It works in Firefox and, I believe, IE7. It appears that with some number of nested structures, the code does not execute. Take a level or two out and it works. The code below is nonsense, but illustrates the problem. This works: javascript: for( a=1;a<=10;a++ ) { for( b=1;b<=10;b++ ) { if( q<1000 )
7
2754
by: Amir Michail | last post by:
Hi, I would like to add a submission bookmarklet to my app that takes the current selection and pastes it into the app's rich text editor while preserving formatting. It should work in at least Firefox & IE. Any pointers on how this could be done? Are there any examples that I can look at? Amir
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.