Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Variable in JavaScript

Posted on 2012-03-30
8
Medium Priority
?
343 Views
Last Modified: 2012-03-30
I am trying to pass a javascript variable to another html page, the code is below.
The first code gets the URL from where the page was loaded from.  The second script opens up the page javascript.html and sends var1 and var2 so I can use them.  this all works perfectly.  What I want to do is pass the value "parent.location" as var1.  Hitting a road block.  




FirstCode.
<script type="text/javascript">

function getParent(){

alert(parent.location);

}

</script>

Second Code.

<script type="texas/javascript"
src="javascript.html?var1=bob&var2=frank">
</script>
0
Comment
Question by:rbm1tch3ll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 6

Expert Comment

by:bartvd
ID: 37787757
I don't it exactly. Do you load Firstcode using SecodeCode? Then why would you pass parent.location, because you already have it in Firstcode?
0
 

Author Comment

by:rbm1tch3ll
ID: 37787775
No, I am looking up the parent.location then I am calling a page that does processing via the second code.
0
 
LVL 6

Expert Comment

by:bartvd
ID: 37787798
Try this:





<script type="texas/javascript"
src="javascript.html?var1="+parent.location+"&var2=frank">
</script>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:rbm1tch3ll
ID: 37787831
Nope doesn't work.
0
 
LVL 6

Expert Comment

by:bartvd
ID: 37787866
You should put the javascript in a javascript file. You could call this file javascript.js, Inside it there should only be javascript, so without the script tags.
0
 

Author Comment

by:rbm1tch3ll
ID: 37787886
Still doesn't work, here is my code.

TEST.HTML

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript">

function getParent(){

alert(parent.location);

}

</script>
</head>

<body>

<script type="text/javascript"

src="test.js">
</script>
<script type="text/javascript">
document.write("<p>" + parent.location + "</p>");
</script>

<body>

</body>
</html>


TEST.JS
// JavaScript Document
src="javascript.html?var1="+parent.location+"&var2=frank">
0
 
LVL 6

Accepted Solution

by:
bartvd earned 2000 total points
ID: 37787910
Sorry, I do not get exactly what is your goal. Do you only want to call another javascript file, or do you want to load another html file? If so, you should not use <script src="..."> , but a frame.
0
 

Author Comment

by:rbm1tch3ll
ID: 37787930
I am trying to send the parent.location to another html file via URL Variable var1.  It works perfectly sending a hard coded ...var1=Bob  over to the html file.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

705 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