JavaScript - Javascript In Href With Url Link
is it possible to link to a page and then run a javascript all in the same href?
for example, i want to redirect back to the home page after a user makes a comment and show the hidden comment div this is my javascript command: Code: <a href="javascript:InsertContent('competitiveevents'); RemoveContent('stories'); InsertContent('blog-comments');"> but can i do something like this..? Code: <a href="../index.php:javascript:InsertContent('competitiveevents'); RemoveContent('stories'); InsertContent('blog-comments');"> Similar Tutorialsi have a little function that uses a checkbox to turn off or on a map layer Code: function toggleGeoXML(id, checked) { if (checked) { var geoXml = new GGeoXml(layers[id].url); layers[id].geoXml = geoXml; if (layers[id].zoom) { map.setZoom(layers[id].zoom); } else { map.setZoom(1); } if (layers[id].lat && layers[id].lng) { map.setCenter(new GLatLng(layers[id].lat, layers[id].lng)); } else { map.setCenter(new GLatLng(39.909736,-35.859375)); } map.addOverlay(geoXml); } else if (layers[id].geoXml) { map.removeOverlay(layers[id].geoXml); } } i'm trying to use an image instead of a checkbox (can be a styled button or a link) the problem is trying to get rid of the "checked" part of the function and integrate it with a normal link but still toggle it off and on this check box input works Code: <input type="checkbox" value="" id="name id of layer" onClick="toggleGeoXML(this.id,this.checked)" /> ive seen loads of ways of showing and hiding layers but nothing that seems relevant to this instance ive tried loads of different things like Code: <a id="name id of layer" href="#" onClick="toggleGeoXML(this.id,this.checked);return false;">on/off</a> also removing the checked part in the function - the link turns layer on but then wont turn it off ie: Code: <a id="name id of layer" href="#" onClick="toggleGeoXML(this.id);return false;">on/off</a> i'm sure its something stupid but ive been looking at this all afternoon and just keep going round in circles thx Hello, I have a site that uses JS to swap images e.g. user clicks on a thumbnail and then the main image changes to show the thumb they've clicked on. So now I'd like that main image to link somewhere, and to change where it links to when the thumb is clicked on also. The link updates ok using my JS, but the shadowbox always loads the flash using the same image variable, not the new one my JS is specifying. Here's my code: Image in Source Code: Code: <div id="show_main_image"> <a href="http://www.mysite.co.uk/zoom/zoom.swf?image=http://www.mysite.co.uk/uploads/1234153173_original_1.jpg" rel="shadowbox;width=600;height=400" id="myAnchor"> <img src="../thumbnails/phpThumb.php?src=/home/sites/mysite.co.uk/public_html/uploads/1234153173_original_1.jpg&w=333&h=284" border="0" name="mainimage" alt="some alt"/></a> </div> Thumb in Source code: Code: <div id="thumbpics"> <p><a href="javascript:selectPicture('1234153173','1');"><img src="../thumbnails/phpThumb.php?src=/home/sites/mysite.co.uk/public_html/uploads/1234153173_thumb_1.jpg&w=50&h=50" border="0" class="thumbpic" alt="some alt"/></a> <a href="javascript:selectPicture('1234153173','2');"><img src="../thumbnails/phpThumb.php?src=/home/sites/mysite.co.uk/public_html/uploads/1234153173_thumb_2.jpg&w=50&h=50" border="0" class="thumbpic" alt="some alt2"/></a></p> </div> Javascript to change the main image: Code: function selectPicture(uniqueid,imgno) { var filenamepic = '../thumbnails/phpThumb.php?h=333&w=284&src=../uploads/' + uniqueid + '_original_' + imgno + '.jpg'; var linkurl = 'http://www.mysite.co.uk/zoom/zoom.swf?image=../thumbnails/phpThumb.php?h=333&w=284&src=../uploads/' + uniqueid + '_original_' + imgno + '.jpg'; document.getElementById('myAnchor').href=linkurl; document.mainimage.src=filenamepic; } So the document.mainimage.src bit works, as it updates the main image, the link is updated but the shawdowbox and Flash is always showing the image it is first sent when the page is loaded. Does anyone have any ideas on how to get round this? Thanks, Nicola Hi-- I have a link that has an mp3 sound as its href: Code: <a href="sounds/genealogy.mp3" class="track track-default">this is a link</a> Unfortunately, I also need that same link to go to a part on the site (href=#greenhouse) so that the sound plays on that part of the site. Does anyone know how to accomplish this? I am imagining it would be with javascript, but honestly, I do not know. Any help would be greatly appreciated. Many thanks...! Hi, here is what I am trying to do, mind if I sound simple this is my first major javascript attempt. You click the checkbox and it changes a link. You click the checkbox again and it changes it back. So you have a page with a link : <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5RSNVHTY5D6RN" id="pay"><img src="go.gif"></a> and a checkbox : <a nohref style="cursorointer;color:blue;text-decoration:underline" onclick="changeTarget()"><input type="checkbox" OnClick="changeTarget()" checked="yes" name="opt-in" id="opt-in" align="center" /></a> </p> Clicking the checkbox runs the javascript function ChangeTarget(). Here is what I want the javascript to do: Code: 1. Write current pay value to variable 2. Compare variable to paypal link -3. change to clickbank link -else change to paypal link. Here is the code I have tried that doesnt work: Code: <script type="text/javascript"> var link = document.getElementById('pay'); function changeTarget() if(link == "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5RSNVHTY5D6RN") document.getElementById('pay').href="http://1.60years.pay.clickbank.net"; else document.getElementById('pay').href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5RSNVHTY5D6RN"; </script> Any help would be very much appreciated, I don't know why it isnt working. It just doesnt do anything when you click it. I know the following DOES work, but it only changes the link to the value chosen... no way of changing it back when you click the checkbox a second time. Code: //WORKING CODE <script type="text/javascript"> function changeTarget() { document.getElementById('pay').href="http://1.60years.pay.clickbank.net"; } </script> Any ideas why Code: <a href="#" title="" onClick="alert(this.parentNode.childNodes[0].innerHTML);"> works but Code: <a href="javascript:alert(this.parentNode.childNodes[0].innerHTML);"> doesn't? In the second case, my error console says this.parentNode is undefined. Hello I am trying to display an image (url stored in a variable) in an iframe, and write some text (which is also stored in a variable) to a div when the user clicks on another image. (hope that makes sense!) The image display part works fine, but I cant find out how to make the part of my javascript which writes the text work. My code is below, I think the problem is to do with the OnClick event but I'm not sure. Any help you can offer might save what little hair I have left! [CODE] ******************************************** This script displays the image in the iframe <script type="text/javascript"> function fitTable(Jvar) { var swidth1= window.innerWidth-230; var sheight1= window.innerHeight-170; var swidth2= document.body.clientWidth-200; var sheight2= document.documentElement.clientHeight-170; if(window.innerWidth) { //checking for browsers that support window.innerWidth document.getElementById("divone").style.width = swidth1 + "px" document.getElementById("divone").style.height = sheight1 + "px" } else if (document.body.clientWidth) { //checking for browsers that support document.body.clientWidth document.getElementById("divone").style.width = swidth2 + "px" document.getElementById("divone").style.height = sheight2 + "px" } var txt=document.getElementById("divdescr") txt.innerHTML="Some Content"; } window.onload=fitTable; window.onresize=fitTable; </script> **************************************** This script writes the text in the div <script language=javascript> function swDescrip(Jvar) { document.getElementById('divdescr').innerHTML = Jvar;} </script> ****************************************** This is the ASP code: <% RS.MoveFirst For d = 1 to recs %> <div ID=d> <% ***************************************************** What I really want is for this bit to display the image in the iframe AND write the text into the div when I click the image in RS(2) desc(d) = "<p>" & RS(1) & "</p>" Response.Write "<A HREF=" & RS(3) & " target='iframe'><img src=" & RS(2) & " width=200 height=120 border=0 onClick = javascript:swDescrip(" & desc(d)) & ") alt='click to display photo' /></a><br>" ****************************************************** %> This bit works OK if I click it but its not what I want <a href="javascript:swDescrip('<%= desc(d)%>')">click</a> ***************************************************** </div/> <% d = d+1 RS.MoveNext Next %> Hi, I am trying to add one image in footer of my application. Code: <div class="rightLinks"> <a href="#"><script src=https://seal.somesign.com/getseal?host_name=www.validsite.com&size=S&use_flash=NO&use_transparent=NO&lang=en></script></a> </div> But this is not working. Please let me know, what is wrong in it. And how can we correct it. Thanks!! Regards, Neha Hi, I am trying to write some code (not my main function in my job) to have a variable be inserted in the middle of a "<a href>" tag. I created an XML file and I am parsing it with XSL and that is working well. In my XSL code I have the following (and it is working): Code: <xsl:for-each select="documents/data[frequency='Daily']"> <script>var meetingIndicator = <xsl:value-of select="meetingIndicator"/>; </script> <tr> <td class="tableLink"><a href="" onMouseover="showmenu(event,linkset[0], '450px')" onMouseout="delayhidemenu()"><xsl:value-of select="meetingCategory"/></a><script>document.write(meetingIndicator);</script> </td> <td><xsl:value-of select="meetingCategory"/></td> <td> <xsl:value-of select="duration"/> </td> <td> <xsl:value-of select="purpose"/> </td> <td> <xsl:value-of select="idealFor"/> </td> <td> <xsl:value-of select="instructions"/> </td> <td class="tableLink"> <a><xsl:attribute name="href"> <xsl:value-of select="documentURL"/></xsl:attribute> <xsl:value-of select="supportingDocuments"/></a> </td> </tr> </xsl:for-each> </table> In this part of the code: Code: <td class="tableLink"><a href="" onMouseover="showmenu(event,linkset[0], '450px')" onMouseout="delayhidemenu()"><xsl:value-of select="meetingCategory"/></a><script>document.write(meetingIndicator);</script> I want to replace the 0 in (event,linkset[0], '450px') with the "meetingIndicator" variable (or even the "<xsl:value-of select="meetingIndicator"/>;") but I don't know how to. I can call the "<xsl:value-of select="meetingIndicator"/>;" and it displays the correct value from the XML file. i just need to know how to place that in the "event,linkset[0]" part of the "a href" tag. I guess it is going to be pretty easy but I have been googling and playing it since yesterday and i am not having any luck. Thank you. Hi, I am making a link to the current url and adding ?XXXX to the end of the URL. I have done this like so: Code: <UrlAction Url="javascript:q=(document.location.href);void(open((q)+'?XXXX,'_self','resizable,location,menubar,toolbar,scrollbars,status'))"/> This works perfectly. However I need to add an If statement in this code which does the following: If (there is a ? already in the current url) add &XXXX instead. Can anyone help me add this in? Thanks I have a page that loads various "applications" into an iframe inside the main page. One of the applications loaded calls a javascript function that is loaded with the "application" page. It works great in Safari, Chrome & Firefox but error's out in IE8 - "Object doesn't support this action". Anyone know why ? Have other calls that work but this one is the only one that uses href Thanks, JerryB [CODE] <div id = 'trainingsubmitbutton' style='display:none;'><a href='javascript: submitdata(0)'>Submit This Record</a></div> [CODE] Hi, I'm using the following Javascript code to show a div layer depending on the URL Code: <script type="text/javascript"> if (location.href.match(/folder/)) { document.getElementById("div-layer").style.display="block"; } </script> This works perfectly when I visit http://www.domain.com/folder but I do not want it to match any subfolders beneath /folder, for example: http://www.domain.com/folder/sub-folder http://www.domain.com/folder/sub-folder2 etc. Does anyone know how I can modify the code to only match /folder or /folder/ and no subfolders beneath it? Thank you in advance. 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 I'm using <base href> to set my HTML path for links, and chdir() to set PHP's base path. (Entering site at www.mysite.com/account then resetting my paths back to root for simplicity). Both of these are working fine, however I've found Javascript ignores <base href> so it's working directory is still a subfolder of root. OK - so I could add '../' to all Javascript links (which is what I was trying to get away from!) but I've read that it's only IE that ignores <base href> and other browsers accept it. This will mean my links break unless I either stop using <base href> entirely and go back to using '../' in ALL links, or I can find a way to set Javascript's base link pointer... This is driving me crazy! Any ideas of how to do it? Can someone tell me how to make a close button for this? The close button I currently have here makes the IMAGE2 disappear but I cannot see IMAGE1 until the time runs out on the setTmeout. I want to be able to click the closeX and close out the whole script leaving IMAGE1 showing. Here is what I have: Code: <table border="0" width="650" id="table1" cellspacing="0" cellpadding="0" bgcolor="#000000" height="350"> <tr> <td align="center"> <script type="text/javascript"> window.onload = function () { setTimeout(function () { var div = document.getElementById('hideOverlay'); div.innerHTML = 'IMAGE1 GOES HERE'; }, 6000);} </script> <div id="hideOverlay"> <table border="0" width="650" id="table1" cellspacing="0" cellpadding="0" height="350"> <tr> <td align="center" width="650" height="350"><a style="text-decoration: none" href="javascript:void(0)" onclick="var lyr =document.getElementById('hideOverlay'); lyr.innerHTML='';"/><font color="#666666" size="2">Close [x]</font></a>IMAGE2 GOES HERE</td> </tr> </table></div> </td> </tr> </table> </div> in a javascript file that contains the following code, is there a way to hyperlink the word ELEPHANT ? $j('#message').html("white ELEPHANT"); Sup gents. Im trying to wrap some html code inside javascript. Problem is i want the picture here to link me to another page, im inserting the link command inside the picture tag put still the link isnt happening. Ive written in a wrong way? Code: document.writeln('<div id="Apartments"><table width="512" height="723" bgcolor="#666633">\n\n <tr>\n <th width="269" height="246" scope="col"><table width="243" height="208" border="1">\n <tr>\n <th height="23" colspan="2" scope="col">Apartment Fola<\/th>\n <\/tr>\n <tr>\n\n <td height="23" colspan="2"><img src="Images\/tn_G1-pokoj.jpg" alt="Fola" width="235" height="139" <a href="apartmentfola.html">/a> <\/> Hi, is it possible to make a external javascript link by giving all the external links a class name then use getelementbytagname in the js file with a function to alert the hes leaving the website and let him choose if he wants to stay or leave. well thats what im trying to do but i dont know how to write the function for it maybe i could get a suggestion or a link to agood tutorial. / thanks lisa I have a simple problem. I want to add the current page's url to a link, like this: <code> <a href="http://www.somesite.com/somepage.aspx?a="> </code> After the 'a=' I need to add javascript that will return the current url. It can be the full url (example: http://www.codingforums.com/newthrea...=newthread&f=2) or a partial one (example: /newthread.php?do=newthread&f=2). Can someone help me with an example? Hi, I'm pretty ignorant about Java and was wondering what the technique is to have different tabs for links on a page? (i.e. you can look through different categories while staying on the homepage). An example of what I mean is at the bottom of this page: http://www.huffingtonpost.com/ Any help would be much appreciated! I've just started to learn Javascript at college, and I made a little code that traps people in a dialogue box loop. var escape = 0 for(escape === 0; escape <= 1 confirm("Going somewhere?") I want to know if there is a site, or a possibility I can start this code, simple by sending friends a URL they can click on. For completely innocent purposes, of course. Thanks! |