rbm1tch3ll
asked on
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=f rank">
</script>
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=
</script>
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?
ASKER
No, I am looking up the parent.location then I am calling a page that does processing via the second code.
Try this:
<script type="texas/javascript"
src="javascript.html?var1= "+parent.l ocation+"& var2=frank ">
</script>
<script type="texas/javascript"
src="javascript.html?var1=
</script>
ASKER
Nope doesn't work.
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.
ASKER
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.l ocation+"& var2=frank ">
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=
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.