JavaScript - Using Javascript In A Bookmarklet To Alter A Url
Simple enough, one would think, but I'm rusty and haven't done this kind of thing in years.
All I need to do is take the current page's url and replace/add a bit into the URL at the appropriate place. For Example, if this is the Current Page URL: Code: http://www.mysite.com/section/main.php?p=1 I want to be able to use the bookmarklet to change it to: Code: http://www.mysite.com/section2/main.php?p=1 This is all I've got for it so far. Probably botched that up too. Code: javascript:(function(){var%20a=document.URL.split("/section/");var%20newURL="www.mysite.com/section2/"+a;}) Similar TutorialsHello all! I'm having a bit of an issue here with my lastest project. What I'm trying to do is have a menu that a user would click one of two links which would change the targeted iFrame, then repeat for two more options, and again for two more. It is essentially a filtering system for videos (the best way for you to see what I mean is to check out http://grph.cmwdesign.ca). My actual issue here is the changing of the iframe href, and on top of that, I seem to not to be able to properly get my functions to run all the time. Here is my Javascript: Code: var categoryLink=new Array(); var counter; var link = ""; categoryLink[0] = ""; categoryLink[1] = ""; categoryLink[2] = ""; counter = "0"; $(document).ready(function() { $(".atonal").live('click', function() { { alert("sometext"); if (categoryLink[0]=="") { categoryLink[0] = "atonal"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); else { categoryLink[0] = ""; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); } }); }); $(document).ready(function() { $(".tonal").live('click', function() { alert("sometext"); if (categoryLink[0]=="") { categoryLink[0] = "tonal"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); else { categoryLink[0] = ""; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); } }); }); $(document).ready(function() { $(".being").live('click', function() { alert("sometext"); categoryLink[1] = "being"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); if (categoryLink[1]=="") { categoryLink[1] = "being"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); else { categoryLink[1] = ""; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); } }); }); $(document).ready(function() { $(".doing").live('click', function() { alert("sometext"); if (categoryLink[1]=="") { categoryLink[1] = "doing"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); else { categoryLink[1] = ""; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); } }); }); $(document).ready(function() { $(".abstract").live('click', function() { alert("sometext"); if (categoryLink[2]=="") { categoryLink[2] = "abstract"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); else { categoryLink[2] = ""; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); } }); }); $(document).ready(function() { $(".documentary").live('click', function() { alert("sometext"); if (categoryLink[2]=="") { categoryLink[2] = "documentary"; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); else { categoryLink[2] = ""; $("a.frame").attr('href', categoryLink[0] + categoryLink[1] + categoryLink[2]); } }); }); and the HTML in question: Code: <table> <tr> <td height="35" width="210" valign="top">choose your sound</td> <td width="165" valign="top"><a href="#" id="atonal">atonal sounds</a></td> <td width="165" valign="top"><a href="#" id="tonal">tonal sounds</a></td> </tr> <tr> <td height="35" width="210" valign="top">choose your text</td> <td width="165" valign="top"><a href="#" id="being">being words</a></td> <td width="165" valign="top"><a href="#" id="doing">doing words</td> </tr> <tr> <td height="35" width="210" valign="top">choose your image</td> <td width="165" valign="top"><a href="#" id="abstract">abstract images</a></td> <td width="165" valign="top"><a href="#" id="documentary">documentary images</a></td> </tr> </table> I'm no Javascript wiz, so I'm sure I'm probably not going about this entirely the correct way. Any suggestions would be great! Hi there, I hope this is the right Forum for asking this. I'm trying to build a Bookmarklet for our Institute, which should work with our library repository. The idea is to consult a SQL search within the repository using the serial number of an article or book which is imported into the bookmarklet via getSelection. Then, after the search query is completed, the repository homepage prompts to the results page. This is where I get stuck. The bookmarklet should now simply show a prompt window saying: do you see a found result on this page? Yes or No. If the user clicks nno, the bookmarklet should forward to the import page, if Yes, the entry is already in the repository and the import is unneccessary. javascript:Qr=document.getSelection();if(!Qr)%7Bvoid(Qr=prompt('Please%20type%20repository&20Nr.:',' '))%7D;if(Qr)location.href='http://dali.biologie.uni-ulm.de/refbase-0.9.5/search.php?formType=sqlSearch&submit=&citeStyle=&citeOrder=&sqlQuery=SELECT+author%2C+title%2C+year% 2C+publication%2C+volume%2C+pages+FROM+refs+WHERE+doi+RLIKE+%22'+escape(Qr)+'%22+OR+notes+RLIKE+%22' +escape(Qr)+'%22+ORDER+BY+year+DESC%2C+author&showLinks=1&showRows=30&viewType=Web'; if(confirm('Is%20the%20article%20already%20in%20the%20repository?')) location.href='http://dali.biologie.uni-ulm.de/refbase-0.9.5/import_modify.php?formType=importID&submit=Import&showSource=1&sourceIDs='+escape(Qr) I hope this is not too confusing. Thanks to anyone for help, and have great holidays! Hi, I'm trying to make a JavaScript where when it's clicked, two alert input boxes appear and the user inputs two Facebook users' ID numbers. The script should then load an iFrame with: ttp://www.facebook.com/"+s+"?and="+s2+" Where "s" and "s2" are the variables. Why is the following not working? Code: if (typeof jQuery == 'undefined') { var jQ = document.createElement('script'); jQ.type = 'text/javascript'; jQ.onload=runthis, runthis2; jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'; document.body.appendChild(jQ); } else { runthis(), runthis2(); } function runthis() { if ($("#wikiframe").length == 0) { var s = ""; s = getSelText(); if (s == "") { var s = prompt("Person 1"); } if ((s != "") && (s != null)) { $("body").append("\ function runthis2() { if ($("#wikiframe").length == 0) { var s2 = ""; if (s2 == "") { var s2 = prompt("Person 2'"); } if ((s2 != "") && (s2 != null)) { $("body").append("\ <div id='wikiframe'>\ <div id='wikiframe_veil' style=''>\ <p>Loading...</p>\ </div>\ <iframe src='http://www.facebook.com/"+s+"?and="+s2+"' onload=\"$('#wikiframe iframe').slideDown(500);\">Enable iFrames.</iframe>\ <style type='text/css'>\ #wikiframe_veil { display: none; position: fixed; width: 100%; height: 100%; top: 0; left: 0; background-color: rgba(255,255,255,.25); cursor: pointer; z-index: 900; }\ #wikiframe_veil p { color: black; font: normal normal bold 20px/20px Helvetica, sans-serif; position: absolute; top: 50%; left: 50%; width: 10em; margin: -10px auto 0 -5em; text-align: center; }\ #wikiframe iframe { display: none; position: fixed; top: 10%; left: 10%; width: 80%; height: 80%; z-index: 999; border: 10px solid rgba(0,0,0,.5); margin: -5px 0 0 -5px; }\ </style>\ </div>"); $("#wikiframe_veil").fadeIn(750); } } else { $("#wikiframe_veil").fadeOut(750); $("#wikiframe iframe").slideUp(500); setTimeout("$('#wikiframe').remove()", 750); } $("#wikiframe_veil").click(function(event){ $("#wikiframe_veil").fadeOut(750); $("#wikiframe iframe").slideUp(500); setTimeout("$('#wikiframe').remove()", 750); }); } function getSelText() { var s = ''; if (window.getSelection) { s = window.getSelection(); } else if (document.getSelection) { s = document.getSelection(); } else if (document.selection) { s = document.selection.createRange().text; } return s; } Hi, I am trying to build a bookmarklet to use on the swiss legislation website. All the pages are available in several languages and I want to be able to switch with one button from french to german and from german to french. As an example, the URLs are as follow for the same page: in French: http://www.admin.ch/ch/f/rs/311_0/index2.html in German: http://www.admin.ch/ch/d/sr/311_0/index2.html So I built quite easily two bookmarklets to switch FR-DE and DE-FR: Code: javascript: var str = window.location.pathname;str = str.replace("f/rs", "d/sr");window.location = str; Code: javascript: var str = window.location.pathname;str = str.replace("d/sr", "f/rs");window.location = str; But when I try to get a single script by using if/else, I cannot manage to have the "else" part working: Code: javascript: var str = window.location.pathname; if (location.pathname.indexOf("d/rs") < 0) { str = str.replace("f/rs", "d/sr"); window.location = str; } else { str = str.replace("d/sr", "f/rs"); window.location = str; } Thinking it might have to do with str.replace, I tried an easier variant, but even this one does not work, the "else" part is never called: Code: javascript: var str = window.location.pathname; if (location.pathname.indexOf("d/rs") < 0) { str = str.replace("f/rs", "d/sr"); window.location = str; } else { alert('no'); }; I would appreciate any help on the matter... thanks in advance, RJ Can someone tell me what I am doing wrong here... This returns "Button Not Found" Code: javascript:var nam="http://apps.facebook.com/onthefarm/giftaccept.php?senderId=547766125&gift=haitibackpack_item_single&timestamp=1285776944&ref=gift_accept_tab&key=6870697de39960508737349c7a3f1363%24%24ggM3T%2CPU2YKM2l0mNrM%28U%28b%21eHAoclFCBgwg49%21S34GWkEXxTekFN_Fkx5%2AUZPcNMEOj&signature=a86a9e11aab0051e3fde676a9abe4283&srcapp=FarmVille"; nam="actions["+nam.replace(/\&/g, "&")+"]"; var els=document.getElementsByName(nam); if(els.length == 0) alert("Button not found"); else els[0].click(); This prompts me to enter a URL...I enter the EXACT same URL as in the above example and it works fine, clicks the button which brings me to the desired page. Code: javascript:var nam=prompt('enter URL Please'); nam="actions["+nam.replace(/\&/g, "&")+"]"; var els=document.getElementsByName(nam); if(els.length == 0) alert("Button not found"); else els[0].click(); Thanks Edit: Before you ask...I've tried in Chrome, IE and Firefox. It does not appear to be an issue with the length of the JS. I get the same results as above regardless of which (valid) URL I use. Hello all i need to be able to make small peace of js code that the user can drag to is IE browser and then invoke it on the page . Hi, I want to open a new window and then execute some js function on that window. My code looks like this: Code: windowObjectReference = window.open("http://some_page.html","name"); windowObjectReference = window.open("javascript:(some_function('param1');)","name"); Is it possible to do activate bookmarklet thru js on new window? I'm trying to write a bookmarklet to automatically follow a specific link on a page without manually clicking or selecting the link. It's for the Facebook game Hatchlings. Each time I view someone's page to collect an egg, it has the following text: You found an egg! Add it to your basket. "Add it to your basket." is the clickable link, but has a different URL embedded in it each time I visit the page. Is there a way to create a bookmarklet to strip out the embedded URL and go to the link without actually clicking on "Add it to your basket." ? Thanks in advance for the help. Hey all - I need a java bookmarklet that does a real simple thing. I need to take the current URL (ie, where the user is when they click the bookmarklet) and append it to a static URL and return the text on the resulting page. For example: The user is at http://google.com The user clicks the bookmarklet. the bookmarklet takes http://google.com and appends it to http://example.com/outside_create.ph...ey=555&url=URL HERE where you see the URL HERE text. That PHP script echos a simple line of text (a shortened URL actually). Then I want that result from the outside_create.php file to be displayed in a window back to the user. Is this even possible? Basically I need to know how to append location.href to a static URL and how to get the resulting content from the static URL.. Hi, I've written a function to change the font, this is working in IE but not in FF or Chrome. No errors come up in Firebug. Once this is working in both browsers I will change the function to gradually increase the size of the font to make it look as if the font is growing. This is why I haven't just assigned a class to the text. URL of the site with the script is http://dev.creativepanda.co.uk/ Function in question is - Code: function alterFontSize(){ var sizeElem = document.getElementById('sizeTest').style; if(reverse == 0 && currentFontSize < endFontSize){ currentFontSize = endFontSize; sizeElem.fontSize = currentFontSize; } } Thanks for any help. hi guys, How could I make this useful dictionary bookmarklet open in a new window? javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.g etSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange( ).text));var%20e=(document.charset||document.characterSet);if(t!=''){location.href='http://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e;}else{location.href='http://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e;}; Its the "To English" bookmarklet as featured on lifehacker. Thanks! I'm not very well versed in javascript. I'm trying to make a bookmarklet that when I click it will either append text to what I've already written or insert the predefined text at the cursor's position in a textarea. Also the browser I'm trying to do this on is Chromium. Here's what I have: Code: javascript:void((function(){document.getElementsByTagName('textarea')[0].value='ಠ_ಠ'})()) ...but this of course changes the entire value of the text field to: ಠ_ಠ ...rather than appending or inserting at the cursor position. I'm guessing append would be the simplest, though cursor position would be most efficient. So if you can help in anyway, please do! Thanks. I have a multiple fields on my page and wish to have a reusable javascript to update the previous box with the selction made. how would this be done Code: <form name="form1" method="post" action=""> <p> <input type="textone" name="textfieldone" id="textfieldone"> </p> <p> <select name="selectone" onChange="UpdatePreviousField()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> <input type="texttwo" name="textfieldtwo" id="textfieldtwo"> </p> <p> <select name="selecttwo" onChange="UpdatePreviousField()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </p> <p> </p> </form> Hi all, I've been trying to teach myself Javascript to figure out this problem, but I'm apparently not learning what I need to. The objective is this: I want to have a div appear below my mouse when mousing over different parts of my website. I know how to swap out the background images, I know how to change the div's sizes... It's just that I'm using one div, and in order to get this right, I need it to be positioned in different places under the mouse each time the image changes. I've got a cross-browser mouse-follow worked out, I just don't know how to edit the "divvx" and "divvy" variables when I mouse over the "boxtest" div. Here is the code I'm working on, maybe I'm just missing something obvious? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script type="text/javascript"> var divvx=22, divvy=22; function doMouseMove(e){ var posx=0;var posy=0; var e=(!e)?window.event:e;//IE:Moz if (e.pageX){//Moz posx=e.pageX+window.pageXOffset; posy=e.pageY+window.pageYOffset; } else if(e.clientX){//IE if(document.documentElement){//IE 6+ strict mode posx=e.clientX+document.documentElement.scrollLeft; posy=e.clientY+document.documentElement.scrollTop; } else if(document.body){//Other IE posx=e.clientX+document.body.scrollLeft; posy=e.clientY+document.body.scrollTop; } } else{return false}//old browsers var mydiv=document.getElementById('curicon'); mydiv.style.left=(posx-divvx)+'px'; mydiv.style.top=(posy-22)+'px'; } document.onmousemove=doMouseMove function MM_callJS(jsStr) { //v2.0 return eval(jsStr) } </script> <style type="text/css"> <!-- #curicon { background-image: url(resources/cursors/Inactive_Halo.png); height: 44px; width: 44px; position: absolute; top: -80px; left: -80px; } #boxtest { position: absolute; height: 100px; width: 400px; background-color: #0F0; left: 149px; top: 213px; } --> </style> </head> <body> <div id="curicon" name="curicon" style="position:absolute; left:-250px; z-index:2"></div> <div id="boxtest" onMouseOver="MM_callJS('divvx=68')"></div> </body> </html> Thanks, everyone. This has been driving me nuts for an entire week. Hello all, Looking for some help to alter a gallery script, very kindly provided for use he http://monc.se/kitchen/80/lightweigh...ith-thumbnails At the moment, the script creates a gallery with thumbnails from a list of images (from my basic understanding), and I want to add to it so the current code also picks up the text from the alt tag and displays that within a div box positioned absolutely elsewhere on the page, when the main image is displayed. Here is the javascript: Code: var gal = { init : function() { if (!document.getElementById || !document.createElement || !document.appendChild) return false; if (document.getElementById('gallery')) document.getElementById('gallery').id = 'jgal'; var li = document.getElementById('jgal').getElementsByTagName('li'); li[0].className = 'active'; for (i=0; i<li.length; i++) { li[i].style.backgroundImage = 'url(' + li[i].getElementsByTagName('img')[0].src + ')'; li[i].title = li[i].getElementsByTagName('img')[0].alt; gal.addEvent(li[i],'click',function() { var im = document.getElementById('jgal').getElementsByTagName('li'); for (j=0; j<im.length; j++) { im[j].className = ''; } this.className = 'active'; }); } }, addEvent : function(obj, type, fn) { if (obj.addEventListener) { obj.addEventListener(type, fn, false); } else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } obj.attachEvent("on"+type, obj[type+fn]); } } } gal.addEvent(window,'load', function() { gal.init(); }); Here is the HTML, which I have enclosed within a div box positioned absolutely on the page: Code: <ul id="gallery"> <li><img src="images/je_1.jpg" alt="Josef & Erika 1"></li> <li><img src="images/roland_ads_2.jpg" alt="Roland Ads"></li> <li><img src="images/cd_2.jpg" alt="CD Cover 2"></li> <li><img src="images/cd_1.jpg" alt="CD Cover 1"></li> <li><img src="images/je_3.jpg" alt="Josef & Erika 3"></li> <li><img src="images/je_2.jpg" alt="Josef & Erika 2"></li> <li><img src="images/lktrd_poster1.jpg" alt="LKTRD Poster"></li> <li><img src="images/je_4.jpg" alt="Josef & Erika 4"></li> <li><img src="images/inside_1.jpg" alt="Inside Magazine"></li> <li><img src="images/oceanen_4.jpg" alt="Oceanen"></li> </ul> And here is the CSS: Code: /* general styling for this example */ * { margin: 0; padding: 0; } body { padding: 20px; } /* begin gallery styling */ #jgal { list-style: none; width: 170px; } #jgal li { opacity: .7; float: left; display: block; width: 45px; height: 45px; background-position: 50% 50%; cursor: pointer; border: 3px solid #fff; outline: 1px solid #ddd; margin-right: 14px; margin-bottom: 14px; } #jgal li img { position: absolute; top: 0px; left: 200px; display: none; border: solid; border-width:1px; border-color:#DDDDDD; } #jgal li.active img { display: block; } #jgal li.active, #jgal li:hover { outline-color: #bbb; opacity: .99 /* safari bug */ } /* styling without javascript */ #gallery { list-style: none; display: block; } #gallery li { float: left; margin: 0 10px 10px 0; } #capt <!--[if lt IE 8]> <style media="screen,projection" type="text/css"> #jgal li { filter: alpha(opacity=50); } #jgal li.active, #jgal li:hover { filter: alpha(opacity=100); } </style> <![endif]--> I don't really know anything about javascript at all, I'm afraid, so any help anyone can give will be very gratefully received. Hi, It would be easier to explain this if you play mafia wars (or any game that includes intra-game exchange of gifts/items between members) but the actual scripting doesn't require any knowledge of the game. Background Information Mafia Wars is a game on Facebook (and myspace, yahoo etc.) that among other things allows its players to send gifts to each other. Now because different people end up with more things of one type and are short of things of another type, the players have evolved a trading dynamic. Where x number of Item 1 is traded for y number of Item 2. A simple marketplace. And with this territory come scammers. Essentially a player who doesn't go through with his end of the deal. good player sends item to bad player. bad player removes good player from mafia and blocks him for ever contacting him through his facebook profile. This has given rise to my group, among many others, that lists these scammers (identified with their facebook profile ids) as they are reported every day. Now over time the list has grown and it has become difficult and unrealistic to expect people to know who is on the list and who is not. The Requirement A javascript bookmarklet (there are many already servicing different needs of the players) that sits on the browser and tells the user if the person he is about to trade with is a listed scammer or not. The Breakdown The user will click the bookmarklet when he is on the facebook profile of the person he is about to trade with. When clicked the script will pull the facebook profile id from the current page, and then scan a text file located on a third-party server and return with a pop-up box message that reports if the id is listed as a scammer or not. It should be pretty simple to do, except I don't know the first thing about javascript coding. So if there's anyone who can devote a few hours/days to help us out with this it would be greatly appreciated. Thank you. Hi, It would be easier to explain this if you play mafia wars (or any game that includes intra-game exchange of gifts/items between members) but the actual scripting doesn't require any knowledge of the game. Background Information Mafia Wars is a game on Facebook (and myspace, yahoo etc.) that among other things allows its players to send gifts to each other. Now because different people end up with more things of one type and are short of things of another type, the players have evolved a trading dynamic. Where x number of Item 1 is traded for y number of Item 2. A simple marketplace. And with this territory come scammers. Essentially a player who doesn't go through with his end of the deal. good player sends item to bad player. bad player removes good player from mafia and blocks him for ever contacting him through his facebook profile. This has given rise to my group, among many others, that lists these scammers (identified with their facebook profile ids) as they are reported every day. Now over time the list has grown and it has become difficult and unrealistic to expect people to know who is on the list and who is not. The Requirement A javascript bookmarklet (there are many already servicing different needs of the players) that sits on the browser and tells the user if the person he is about to trade with is a listed scammer or not. The Breakdown The user will click the bookmarklet when he is on the facebook profile of the person he is about to trade with. When clicked the script will pull the facebook profile id from the current page, and then scan a text file located on a third-party server and return with a pop-up box message that reports if the id is listed as a scammer or not. It should be pretty simple to do, except I don't know the first thing about javascript coding. So if there's anyone who can devote a few hours/days to help us out with this it would be greatly appreciated. Thank you I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael |