Link to home
Start Free TrialLog in
Avatar of rbm1tch3ll
rbm1tch3llFlag for Afghanistan

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=frank">
</script>
Avatar of bartvd
bartvd
Flag of Netherlands image

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?
Avatar of rbm1tch3ll

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.location+"&var2=frank">
</script>
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.
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">
ASKER CERTIFIED SOLUTION
Avatar of bartvd
bartvd
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.