USing a Variable with == javascript:window.location.href

Posted on 2013-09-25
Medium Priority
Last Modified: 2013-09-25
I first need to say my skills in this area are vary basic and I often have to code Javascript with the help of Google..

This block of code works --  An displays the proper URL vale.
<script language="JavaScript">  document.write(document.referrer); </script>

Open in new window

This block of code where I hard code a URL also works as I need it to.
<INPUT TYPE="button" class="largeButton"  VALUE="Back" onclick="javascript:window.location.href='http://xxxxxx.xxxxxxxxx.net'; return false;" >

Open in new window

But when I try and combine the two functions into one so that the code can be reused with out being updated each time, it breaks.   Everything to the right of  <script language="javascript">   appears as text on the page -- "document.................."
<INPUT TYPE="button" class="largeButton"  VALUE="Back" onclick="javascript:window.location.href=<script language="JavaScript"> document.write(document.referrer) </script> ; return false; " >

Open in new window

So I must not be building the string incorrectly, but I am not sure what I am missing and while Google has found some examples, all are back a few years and so far nothing has helped..

TIA --
Question by:Phonebuff
  • 2
LVL 15

Accepted Solution

Phonebuff earned 0 total points
ID: 39522251
Never Mind Found the Answer --

<script language="JavaScript"> var $link; $link = document.referrer; </script> 
<INPUT TYPE="button" class="largeButton"  VALUE="Back" onclick="javascript:window.location.href=$link; return false;" >

Open in new window

LVL 15

Author Closing Comment

ID: 39522252
Found my own answer --

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
AngularJS web development a very simple procedure. So, to put it, in short, AngularJS’ stand out features are – Two-way data binding, MVC structure, directives, templates, dependency injections and testing.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question