JavaScript - Document.referrer Property
Any help would be awesome and much appreciated!
I'm trying to change an id by referencing the previous site the user was on. In this case the user will be coming from either facebook or linkedin. I'm not sure if i'm calling the referrer property correctly. Again, any help is greatly appreciated! <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script language="JavaScript"> if(document.referrer.toLowerCase().indexOf("facebook") != -1) { document.getElementById("phone").innerHTML = "555.555.5555"; } else if (document.referrer.toLowerCase().indexOf("linkedin") != -1) { document.getElementById("phone").innerHTML = "222.222.2222"; } else { //Default code } </script> </head> <body> <p id="phone">123.456.7890</p> </body> Similar TutorialsHello I am new to javascript and have the following question: Is it normal that the Document.links property only counts links that are placed before the command? example: Code: <body> <script type="text/javascript"> document.write (document.links.length); </script> <p><a href="http://www.youtube.com/watch?v=gt9j80Jkc_A#">Youtube link</a></p> <script type="text/javascript"> document.write (document.links.length); </script> </body> The result is Quote: 0 Youtube link 1 How can I avoid this? Only by putting the code at the end of the document? And since i am asking? Is it possible to search a entire document for a string and replace that string with one command? (don't give me exact solution please just a hint what direction i should be searching in). Kind regards I'm new to JavaScript, just started an adult education class in it. I wrote a simple script to view a list of document properties and their values. This part works in Internet Explorer: for (var prop in document){ p_prop = prop; p_list[i] = p_prop + " : " + document[prop] + "<br />"; but doesn't in FireFox. I was wondering how to get the value of a property in FireFox. Thanks. Hello, I have WordPress installed in a directory of my website, and I'm using an iframe on the homepage to embed the blog. I'm using a javascript code that I found online to automatically resize the iframe based on the content inside of it. This is the code: Code: <script type="text/javascript"> function resizeIframe() { document.getElementById('blog').style.height = document.getElementById ('blog').contentWindow.document.body.scrollHeight + 'px'; } </script> This works perfectly in Google Chrome. However, in Firefox I get this error in the console: Code: Error: Permission denied to access property 'document' Source File: http://mysite.com/index1.html Line: 24 I don't have any experience with javascript, but this makes no sense to me, because it should work since the iframe document is on the same domain and server as the parent page. The parent is "mysite.com/index1.html" and the iframe document is "mysite.com/blog/". Why is Firefox complaining about this? It shouldn't violate the "same origin policy" that I have read about. Any help with getting this to work would be appreciated. Hi all, I have a frame structure (three frames) where the top one is my flash navigation. The navigation itself is quite complex so I have given up on the idea of creating a back button code to control the flash. All I want to do now is to refresh the flash page when browser's back button is pressed. What I would like to do is to set a variable of the previous page I just have been so when I hit browser's back button I know if this page is the same as the variable. In each individual page i would set the varaible to be the previous page. Here are few things I have tried so far and none of them seems to work (even online!) (sections is the name of the main frame) old_page = parent.sections.history.previous; old_page =document.referrer; I tried both of them at the beginning of each page. then used onUnload command in the body tag to call a function on another frame where I have the comparison: function check_history(old_page){ if (old_page == parent.sections.location){ alert(" refresh flash"); } If I use referrer, the value is null (empty) or if I use history the variable is undefined. Has anyone come accross with anything similar? Thank you very much for your help. I have used this script successfully: http://www.javascriptkit.com/script/...2/refer2.shtml However, is there a way to block the following work-around (example only): http://www.their-url.com/redir.php?u...ww.my-url.com/ The redir.php makes it possible to get past the script. A little question: Which referrer gets facebook if I make a getjson to https://graph.facebook.com/someid?callback=? Does facebook get as http referrer the client or my server? this is prob more simple than im thinking but i cant grasp it at the moment.. on the process page for my site, it has a link to view the account i click on that link and then i can click the back link to go back.. when i do, i get a page has expired message the reason is because the original link there is Code: http://www.xxx.com?ms=1 and that ms1 no longer exists after i leave the page because i unset it. once i leave that page so im curious is there a way to have the main url Code: http://www.xxx.com as the referrer when i click on the link so that when i use the back link Code: <a href="javascript: void(0)" onClick="javascript:history.go(-1)">Go Back</a> it can go back to that main page url instead of tring to find the one with ms1 on it.. i just realized i should have posted this is javascript sorry im tired lol Hello, I have very little knowledge of javascript, other than modifying existing scripts, and I can't find anything about this particular problem. I need some help on creating a simple script that will display a div ONLY if the user comes from a certain page within the same site. Not sure if that was clear, but let me try with specifics. There is a link to a page called 'Clients' on the 'About Us' page. If a user goes directly to 'Clients', they should have a normal experience. If, however, they come via the 'About Us' page, I want to display a div at the bottom of the page that will take them back to the 'About Us' page. I know how to get a referrer, and I know how to show/hide divs. I just don't know how to combine the two. Can anyone help? My code is here and it works ... However, I would like my dynamic table to show on the same page as my body and not on a new blank page. I have created a DIV and try playing around with the document.getElementById('monTab').innerHTML but it's not working out for me ... What am i missing ? Regards, Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>new Script - Javascript Cours 11</TITLE> <META content="text/html"; charset="UTF-8" http-equiv="content-type"> <SCRIPT type="text/javascript"> function createTable(){ var Etudiant = new Array(Number(prompt("How many Students will you put in ?",""))); document.write("<table border=\"1\">"); for (var i=0; i<Etudiant.length; i++) { Etudiant[i] = window.prompt("S'il vous plait entrez le nom d'un etudiant " + (i+1) + ".","") alert("Nice to see you "+Etudiant[i]); document.write("<td>"+Etudiant[i]+"</td>"); j = parseInt(prompt("Combien de notes voulez vous calculez ?")); for (h=0;h<j;h++){ notes[h] = parseInt(prompt("S'il vous plait entrez la "+(h+1)+" note de "+Etudiant[i])); document.write("<td>"+notes[h]+"</td>"); } document.write("<tr>"); } document.write("</tr>"); document.write("</table>"); document.getElementById('monTab').innerHTML=Etudiant; } </script> <BODY> <H1>Combien de note voulez vous cumulez ?</H1> <br> <br> <input type="button" name="btnSubmit" value="TRY IT" onclick="createTable()"> <div id="monTab" size="10"> Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ... </div> </BODY> </HTML> I found this line in one of the scripts on javascript.kit <code> if(document.layers|| document.getElementById|| document.all) </code> Could someone give me an idea on why this line would be used in a code? Thank you very much I'm working on a website that will basically embed a widget/frame sent by a handler into a user's current page. The user basically adds a script tag to where they would like the HTML to be. The script tag has their settings and is basically a document.write that calls all the code that we want displayed. So here's my problem. We have a map that we need to add in a specific section, and to get the map we have to call another script tag. So we end up having a script tag (map) embedded in another script tag (the code for the widget/frame) or we end up having to document.write inside a document.write. Now this works just fine and as expected in Firefox, Safari, and Chrome. However, Internet Explorer and Opera wait until the first document.write is completely finished before calling the embedded one. Of course the problem with this, is that it takes the map out of the document's flow and just appends it to the bottom left of the page. Since the rest of the page has already been called, there's no way to move the interior "map" script. Any ideas? Basically just trying to figure out how (if even possible) to render an embedded script tag in Internet Explorer and be able to place it properly. I've tried everything that I can think of, including AJAX and Google's unescape script. Any suggestions, I'd greatly appreciate it. Or even if you've encountered a similar problem, and know that it just isn't possible in IE or Opera, that would be fine too. Thanks in advance! I am sorry the following code is a bit of a mouthful, but I can't find a better way to display the problem. The code works as expected in Chrome, but not in IE and FF. In IE the error is "Object doesn't support this action" and in FF "setting a property that has only a getter". In Chrome there is no error in the console. There are three javascript <script>...</script>s that exist to display a <td> row in a table with a particular graphic depending on the screen width. The odd thing is that in both IE and FF (and of course Chrome), the first two scripts display perfectly well. Why does the third <script> produce an error? It has exactly the same form as the two before it. I can only guess it has something to do with where it occurs Googling the FF error, it has something to do with trying to set a read-only property, but then why do the first two <scripts> work? They are no different (at least I can't see a difference.) Code: <table border="0" width="100%" cellpadding="0" style="border-collapse: collapse" id="table3768"> <script> if (screen.width > 1280) { document.write("<td valign=\"top\" background=\"..\/..\/img\/lesson2.gif\" width=\"840\" height=\"301\">"); } else { document.write("<td valign=\"top\" background=\"..\/..\/img\/lesson.gif\" width=\"369\" height=\"301\">"); } </script> <p> </p> <div align="left"> </table> <table border="0" style="border-collapse: collapse" cellpadding="15"> <tr> <td width="40"> </td> <script> if (screen.width > 1280) { document.write("<td width=\"300\">"); } else { document.write("<td width=\"165\">"); } </script> <font face="Trebuchet MS" color="#808000">Today's lesson is about setting goals...</font></td> </tr> </table> </div> </td> <td rowspan="3"> <table border="0" cellspacing="0" style="border-collapse: collapse" cellpadding="0" id="table3920"> <tr> <td><img border="0" src="../../img/teltopw.jpg" width="550" height="9"></td> </tr> <tr> <td background="../../img/telbarw.jpg"> <p align="center"> <iframe name="ITV" src="lesson1TV.html" marginwidth="0" marginheight="0" scrolling="no" border="0" frameborder="0" width="480" height="376"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe></p> </td> </tr> <tr> <td><img border="0" src="../../img/telbotw.jpg" width="550" height="11"></td> </tr> </table> </td> <td align="center"> <a rel="nofollow" target="_blank" href="http://www.apple.com/quicktime/download/"> <img border="0" src="../../img/quicktimeani.gif" width="129" height="184"></a></td> </tr> <tr> <script> if ((screen.width = 1440) || (screen.width = 1400)) { document.writeln("<td valign=\"top\" width=\"100%\" background=\"\/images\/101online\/listening\/lesson16\/notebot2.gif\" width=\"450\" height=\"50\">"); } else if (screen.width <= 1280) { document.writeln("<td valign=\"top\" width=\"100%\" background=\"\/images\/101online\/listening\/lesson16\/notebot.gif\" width=\"294\" height=\"50\">");; } </script> </td> <td valign="bottom"> </td> </tr> <tr> <td valign="bottom" width="100%"> <div align="right"> <table border="0" cellpadding="5" style="border-collapse: collapse" id="table3926"> <tr> <td align="center"> <a onmousedown="soundManager.play('piano','../../media/mp3/piano.mp3'); return true;" href="javascript: goFull('FULLSCREEN/lesson1full.html','info','width=1020,height=760,left=0,top=0,toolbar=no,scrollbars=no,status=no,directories=no,menubar=no,location=no,resizable=no');"> <img src="../../img/poster1ani.gif" border="0" width="95" height="29"></a> <b><font size="1" face="Arial" color="#000080"> ON DISK</font></b></td> <td align="center"><b><font size="1" face="Arial" color="#000080">OR </font></b> <a onmousedown="soundManager.play('piano','../../media/mp3/piano.mp3'); return true;" href="javascript: goFull('CDRIVE/lesson1Cfull.html','info','width=1020,height=760,left=0,top=0,toolbar=no,scrollbars=no,status=no,directories=no,menubar=no,location=no,resizable=no');"><img src="../../img/poster7.bmp" border="0" width="53" height="30"></a> <b><font size="1" face="Arial" color="#000080"> DRIVE</font></b></td> </tr> </table> </div> </td> <td valign="bottom"> <iframe name="sounds" src="../../pagesounds.html" width="160" height="66" marginwidth="1" marginheight="1" scrolling="no" border="0" frameborder="0"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe></td> </tr> </table> Any light on this would be most welcome! I'm using ccs3PIE with my site. What I want to do is check if a DOM element has a css property like border-radius and then add a class to it. The problem I'm having is that I don't know how to check for the css property. I've been searching for it for a couple of hours now and I can't find anything that seems to work. Any ideas? I've got this JavaScript code that is doing stuff to the content of <TR> rows.. but it's overselecting and I need to filter the <TR>s it selects in the bold line. var theRows = document.getElementsByTagName("TR"); var r = 0; var strTitle = ""; while (r < theRows.length) { try { strTitle = theRows[r].innerText || theRows[r].textContent; strTitle = strTitle.replace(/\n|\r|\t|\^ /g,""); if (strTitle.substring(0,1) == "(") { if (strTitle.indexOf("STAT") == -1) { theRows[r].style.display = "none"; ... continues Below is the rendered html. What I really want to do instead of if (strTitle.substring(0,1) == "(") Is only perform the operation when a row that is using class="ms- formlabel, or maybe has a FieldInternalName. I understand that strTitle is just pulling content, so how do I condition on other properties or strings within the <TR> row given my currently logic? Rendered HTML. <TR> <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader"> <nobr>1. Do you become short of breath or develop chest pain when climbing a flight of stairs?</nobr> </H3></TD> <TD valign="top" class="ms-formbody" width="400px"> <!-- FieldName="1. Do you become short of breath or develop chest pain when climbing a flight of stairs?" FieldInternalName="ShortofBreath" FieldType="SPFieldBoolean" --> <span dir="none"> Thanks for any help or information! I have a page: http://www.girlscoutsmoheartland.org...progsearch.php that works perfectly fine in every browser I try, except for actual IE7 (it even works fine in IE8 emulating IE7). When you search for something on that page and have a display of results, each result has a link that changes a table row's display to visible, and hides the row when clicked again. It doesn't do that in IE7. There are no errors or warning in Firefox's Error Console. But IE7 has an "Error on Page" notice (which does NOT appear in IE8 emulating IE7), that says: Line: 59 Char: 11 Error: Could not get the display property. Invalid argument. The script in question is this, with what would be line 59 indicated: Code: <script type="text/javascript"> <!-- function toggle_visibility(id) { var e = document.getElementById(id); var f = document.getElementById(id + "b"); if(e.style.display == 'table-row') e.style.display = 'none'; else e.style.display = 'table-row'; <<-- This is line 59 if(f.style.display == 'table-row') f.style.display = 'none'; else f.style.display = 'table-row'; } //--> </script> I really don't know what to do, or where to begin. Everything in my limited knowledge seems to be working just fine. Most of my site's visitors use IE8, but enough use actual IE7 that I really need to fix this. Thanks for any help or advice! Liam I had read from books that the constructor property of object is inherited from its prototype. And the prototype can be changed dynamically. New property can be added to or deleted from object even it was created before the prototype change. But I got confused on below codes. Code: function A() { this.title = "A"; } function B() { this.title = "B"; } document.write("<br>"); var b = new B(); document.write(b.constructor); document.write("<br>"); document.write(B.prototype.constructor); document.write("<br>"); B.prototype = new A(); document.write(b.constructor); // Suppose to output "function A() ..." document.write("<br>"); document.write(B.prototype.constructor); document.write("<br>"); B.prototype.constructor = B; document.write(b.constructor); document.write("<br>"); document.write(B.prototype.constructor); document.write("<br>"); But the actual result (both IE and firefox) is Code: function B() { this.title = "B"; } function B() { this.title = "B"; } function B() { this.title = "B"; } function A() { this.title = "A"; } function B() { this.title = "B"; } function B() { this.title = "B"; } Please help me. thanks. I have this simple manual photo slide show. It shows four photos and when you click the next button and it moves one photo over and one photo back for the previous button. I have to moving by changing the CSS property of 'left' by 195 pixels each move. So for it to move next it will subtract 195 pixels from the left property and for moving back it add 195 pixels to the left property. I have the code setup so when you click it changes the property of left to either -195 or 195 pixels but I need it so it actually does the math, not just give it a set value. But I don't know how to do that. Code: function MM_changeProp(objId,x,theProp,theValue) { //v9.0 var obj = null; with (document){ if (getElementById) obj = getElementById(objId); } if (obj){ if (theValue == true || theValue == false) eval("obj.style."+theProp+"="+theValue); else eval("obj.style."+theProp+"='"+theValue+"'"); } } function nextPhoto() { MM_changeProp('fanThumbWrapOne','','left','-195px','DIV') } function prevPhoto() { MM_changeProp('fanThumbWrapOne','','left','195px','DIV') } so where you see -195px and 195px in the functions for nextPhoto and prevPhoto I need those to actually be functions where it subtracts 195px or adds 195px. I am and seem to remain newbie ... I have a JS script that presents a series of "pages" with different questions inside a single HTML file, by rewriting certain <div>s. I have an object like this that contains the questions and information about answer labels etc (the idea is that this should be easy to modify for someone who doesn't know JS): Code: var Questions = [ { "question" : "How good is this?", "labels" : ["excellent","very good","good","bad","very bad","awful"], "page" : 0 , "random" : false , "type" : "default", "varname" : "allgood" }, { "question" : Change[curCase]+"What do you think now?", "labels" : BetterLabels, "page" : 1 , "random" : true , "type" : "default", "varname" : "betteradapt" } ] This object is initialized when the page loads, and a function reads the total number of pages by getting the maximum number of the "page" property across elements. Later, the object is accessed by thenextQuestion() function which uses the "page" property to looks whether each element belongs on the current page , then reads out the properties and presents the question. This works okay. Now the tricky bit: For some questions, their text should be different depending on which case is currently on the screen (Change[curCase]). curCase is different on each page, an integer between 0 and Change.length. I cannot get this to work for the Questions object, probably because the Questions object has been already initialized when the page loaded. How can I get my function nextQuestion() to "re-evaluate" the property "question" for all the elements of the Questions objectwhen nextQuestion() is called , using the current value of "curCase"? nextQuestion() is longer, but the (i think!) crucial bits are he Look whether question belongs on current page and push it onto new array: Code: for (i=0; i < Questions.length; i++) { Questions[i].page = Questions[i].page; if ( Questions[i].page == BlockNum ) { // if the q belongs on the current page QuestionsObjectThisPage.push(Questions[i]); } } Then, extract an array containing the questions, which will then be presented: Code: for (i=0; i < QuestionsObjectThisPage.length; i++) { QuestionsThisPage.push(QuestionsObjectThisPage[i].question) ; } So what I'm looking for is something to change either of these two Object.push() functions so they don't simply take the value they find in the Questions (or QuestionsThisPage) object, but to re-evaluate the code for the "questions" property, taking into account the current value of curCase Phew. I found that really hard to describe; hope it's somewhat clear. Hi, This is my first post while learning Javascript and jQuery as total noob. I have something like this: Code: var desc = "This is your title and here is even more that might be added so that we can get at least 60 characters or so"; var desc = desc.trim().substring(0, 40).split(" ").slice(0, -1).join(" ") + "...more"; alert(shortText ); It is actually being used on a page that calls a description from a MySQL table, but this example fails in exactly the same manner. Although FF and other browsers successfully initiate the script with errors, but IE loops endlessly and freezes up. FireBug reports "reference to undefined property a[d]". Using jQuery 1.6.2. I'm not really sure what property is undefined here and how this can work without freezing IE. Thanks in advance for any help! AJ 1. When creating a new element using the create method, do the zIndex values of all elements that follow it change? If so how do I get the zIndex of all divs with a specific classname within a specified container? I'm working with dynamic drive's 'dhtmlwindow' object class file and have made revisions to it...however this is my first time working with this type of file and while some things are easy to change the zIndex change of the setfocus function does not look like any of my previous scripts. |