Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Variable in JavaScript

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
rbm1tch3ll
Asked:
rbm1tch3ll
  • 4
  • 4
1 Solution
 
bartvdCommented:
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
 
rbm1tch3llAuthor Commented:
No, I am looking up the parent.location then I am calling a page that does processing via the second code.
0
 
bartvdCommented:
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.

 
rbm1tch3llAuthor Commented:
Nope doesn't work.
0
 
bartvdCommented:
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
 
rbm1tch3llAuthor Commented:
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
 
bartvdCommented:
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
 
rbm1tch3llAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now