JavaScript - Can I Set Javascript's Base Href (base Url) For All Relative Links?
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? Similar TutorialsHello, I came across a very odd browser behavior when trying to modify a css class using javascript and at the same time having a base html statement in my html file. Without the base html statement, all browsers work fine and I can change the css class definition using javascript easily. With a base html statement, only FireFox still works while Internet Explorer and Google Chrome dont work anymore. If there is a cross-domain issue, while one browser does work and the others dont? An example of what I'm talking about, with the base statement: http://freebsdcluster.org/~casaschi/...mple-base.html Without the base statement: http://freebsdcluster.org/~casaschi/...le-nobase.html Any idea how to tweak the code in the case with the base html statement in order for the javascript to work with all browser (modifying the class definition) ??? Keep in mind, I dont want a suggestion of another way to change the color, this is only an example. I want to be able to manipulare css classes with javascript when a base html statement is in my html code. This is essentially the code: Code: <!-- --> <base href='http://www.google.com'> <style id='myStyle' type='text/css'> .myStyle { color: red; } </style> <script type="text/javascript"> var lastColor = 'red'; function toggleColor() { lastColor = lastColor == 'red' ? 'green' : 'red'; myObject = document.getElementById('myStyle'); if (myObject.sheet) { myObject.sheet.cssRules[0].style.color = lastColor; } // Mozilla style if (myObject.styleSheet) { myObject.styleSheet.rules[0].style.color = lastColor; } // IE style } </script> <a href="javascript: toggleColor();"><span class=myStyle>click here to toggle color</span></a> Thanks in advance... Hi I am working on a base converting calculator. Same as this calculator on this link. http://www.asknumbers.com/BaseNumberConversion.aspx. I am only working on bases from 2- 10 inclusive. Here is the coding I did but the problem is i cant get the output once the user inputs the "To base". Can some one help. <!-- Base Changing.html <!-- ======================================================= --> <head> <title>Base changing </title> <script type="text/javascript"> function BaseConv() // // { var Xnumber=document.getElementById("dnumberArea").value; var XBase=document.getElementById("dbaseArea").value; //var XBase=parseInt(XBase); var BBase=document.getElementById("bbaseArea").value; //BBase=parseInt(BBase); var exp=Math.log(Xnumber)/Math.log(XBase); //Xnumber=Math.pow(XBase,exp); //log var D=1+ Math.floor(exp); var str=""; count=0; while(count<D){ digit = Xnumber%XBase; Xnumber = Math.floor(Xnumber/XBase); str= digit + str; count++; } document.getElementById("bnumberArea").value=str; } </script> </head> <body> <div style="text-align: center"> <h2>base changing</h2> <hr/> <br><br> Input number <input type="text" id="dnumberArea" size="" Onchange="BaseConv();"/> From base <input type="text" id="dbaseArea" size="" Onchange="BaseConv();"/> <br/><br/> Output number <input type="text" id="bnumberArea" size="" Onchange="BaseConv()"/> To base <input type="text" id="bbaseArea" size="" ;"/> </div> </body> </html> I need someone to link this: thiswebsite.com/12.html then someone clicks on a link, and the url would go to thiswebsite.com/12_1.html The link script has to subtract the ".html" from the original url, then add "_1.html" to the new url. I am pretty sure this is a simple script to make, I just do not have the time to google this and figure this out. I will pay $5 to anyone who fix this problem for me. you can post the solution here, with your paypal email so I can pay you, or email me the solution at hotgoat145@yahoo.com and tell me your paypal email so I can pay you. Im looking for a javascript code, because .htaccess does not work for me. it has to be in javascript, where it is like this <script language='JavaScript' type='text/javascript'> document.write('<a hr'+'ef="ht'+'tp://w'+'ww.mysite'+'.com/1.php">My Site</a>'); </script> Only I have to be able to subtract .php from the URL, and add _2.html to the final URL Here is what I am talking about: Go to this website: http://tehcake.com/video/30rock/2x14%20-%20Copy.html Do you see where it says Backup Links: 1 2 I need it to link to http://tehcake.com/video/30rock/2x14%20-%20Copy(2).html So it does (url of webpage [minus] file extension [plus] (2).html) it should be in javascript or something that can be written in the webpage. 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. 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 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');"> 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 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. here is an example of the problem (and how to produce it): 1) go to http://eataustineat.com/testfolder/index.php 2) type in an 'a' into the text field 3) click "view results" 4) select the first result (ie: Dog Almighty) Notice the javascript slide doesn't happen. In fact, nothing appears to happen. It is suppose to slide the content to the left much like it did when you hit "view results". Why? I hope this clears the problem up some. I have a frameset with 2 frames. I have simple flash video playing in the left frame (jwplayer) with an html menu underneath the will fast forward to a specific time in the video with javascript. Works great. In the right frame I have a pdf document that I want to setup so when the user user clicks the simple link under the video it also goes to a specific page within the pdf document in the right frame. Hope this makes sense and thanks in advance for the help. here is one of the html links from the video menu. Code: <a href="#" class="style1" onclick="player.sendEvent('SEEK',0); return false;">Item 1</a> Can any one please tell me a way to get all the links in a web page using javascript?
Okay, this is a long-winding problem, but I'll do my best to explain it. I am creating a website for my ICT coursework which I have been making using frames as a basis for the layout. On one of the pages, I have included a calendar, which itself is in a frame. Essentially, what I have is a frame within a frame. Certain made up events in the calendar were linked to another page on my site- when you clicked on that link, it closed the calendar frame, and opened the link within the original frame, using this code: Code: "<a href='link.htm' rel="nofollow" target='frame' onclick='window.close();'><center><img src='IMAGE' border='0'></a>" I had to include this within the Javascript file, and because of the original coding, I can't use " "s in the coding, or it breaks the statement, so I can only use ' ' within the two. I got this code from Script Calendar. Initially, this code to open the links worked, closing one frame and opening the link in another. However, now when I click it, it opens in a new window. I really don't know what exactly to edit, as my experience is minimal with Javascript. I know it's very overcomplicated, but I would really appreciate any help at all! Thank you! Hello, I'm having a strange problem. I have a visio diagram displayed on a Sharepoint 2010 page. It's a chart, and each item within it links to a relevant item in a Sharepoint list, displayed in a modal window using a bit of JavaScript. The problem is it works in everything but Internet Explorer! Could anyone help? IE doesn't display any errors. Code: function openDialog(id){ var addString = '&ContentTypeID=0x010093E0E47DAEC14BF5AA399AF47613F91F005BDB7D7682432C4F98DF9B7670EF440C'; var modalUrl = id + addString; options = SP.UI.$create_DialogOptions(); options.url = "../mysharepoint/display.aspx?" + modalUrl; options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback); SP.UI.ModalDialog.showModalDialog(options); } function CloseCallback(result, target) { location.reload(true); } Hi Everyone, I have a strange problem that I can't resolve. Have a look at www.snaptease.co.uk/random.html and you will see a random image every time you refresh. Now look at www.snaptease.co.uk/random1.html and you won't see the image. The only difference is in the js/random.js and js/random1.js each file references. js/random.js uses the same html link to index.html js/random1.js links to individual html files that exist and valid. The working code looks like this: [CODE] images[0] = "<a href = 'index.html'><img src='images/games/aa01q.jpg' alt='album art' title='Do you recognise this album?'></a>";[CODE] The non working code looks like this: [CODE] images[0] = "<a href = 'answers/aa01.html'><img src='images/games/aa01q.jpg' alt='album art' title='Do you recognise this Album?'></a>";[CODE] Even if I enter the full url it makes no difference. Please tell me what I am doing wrong and how to fix it. I've been banging my head over this for a while now so I would appreciate any help. Thanks in advance Martin Below is a javascript function from my website that loops through nodes in an XML file retrieving certain information about those who joined in the current month/year. The part in red creates a link which when clicked runs a function called show() with the relevant i variable value e.g. show(2) for the second node if that is relevant. Anyway the red part works in Chrome but not Internet Explorer (surprise surprise). I did some research which says that .setattribute is not allowed in IE. How can I change the red code to create links for the relevant records which works in IE? Thank you for your help Code: function displaymember() { var d = new Date(); var curr_month = d.getMonth(); curr_month++; if (curr_month < 10) curr_month = "0" + curr_month; var curr_year = d.getFullYear(); for (i = 0; i < x.length; i++) { membershipstatus = (x[i].getElementsByTagName("membership_status")[0].childNodes[0].nodeValue); name = (x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue); body = (x[i].getElementsByTagName("body_type")[0].childNodes[0].nodeValue); ethnicity = (x[i].getElementsByTagName("ethnicity")[0].childNodes[0].nodeValue); sex = (x[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue); seeking = (x[i].getElementsByTagName("seeking")[0].childNodes[0].nodeValue); date = (x[i].getElementsByTagName("date_joined")[0]); month = (date.getElementsByTagName("month")[0].childNodes[0].nodeValue); year = (date.getElementsByTagName("year")[0].childNodes[0].nodeValue); newa = document.createElement("a"); aIdName = "my" + i + "a"; ahref = "#"; aclick = "show(" + i + ")"; newa.setAttribute("id", aIdName); newa.setAttribute("href", ahref); newa.setAttribute("onclick", aclick); newa.innerHTML = name + " | " + body + " " + ethnicity + " " + sex + " with " + membershipstatus + " membership seeks " + seeking + "<br/>"; if (curr_month == month && curr_year == year) { document.getElementById("member").appendChild(newa); } } } I've created a slideshow on our site using the java template at http://www.javascriptkit.com/script/.../jsslide.shtml Are there simple modifications I can make to this code in order to cause clicking on the image links to go straight to them, rather than creating a new window/tab? Thanks for the help. |