By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,249 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,249 IT Pros & Developers. It's quick & easy.

set target frame for jumpURL function

P: n/a
Hi all

I have done lots of VB programming, but am not familiar with JavaScript.

Can anyone tell me how to do this ....?

I have a JS file for a menu system called menu.js

It contains the following function :

this.jumpURL = function(url) {
if(url) document.location.href = url;
}

I want to get the function to select the 'target' frame / page / etc
depending on variables sent to the function.

eg
this.jumpURL = function(url, target) {
if(url) target.location.href = url;

If I then call the function jumpURL (www.abcd.com, InFrame1 )
it should open the page in an inline frame named InFrame1

For some reason I cannot grasp how to make this work.

However, if I change it to :
if(url) InFrame1.location.href = url;
it works fine ( ie.. with the physical name of the frame in the statement ).

SO.......How can I use a variable in place of "InFrame1" ?

or do I need something along the lines of :

if target = "InFrame1" then if(url) InFrame1.location.href = url;
if target = "InFrame2" then if(url) InFrame2.location.href = url;
if target = "InFrame3" then if(url) InFrame3.location.href = url;

This would be the VB style of IF statement - I do not understand the JS
structure yet.

However, this would be very limiting meaning that I would need to modify the
function in the menu.js file every time my html page was changed.

My thanks and appreciation in advance for any assistance.

DaveO

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <d6**********@ctb-nnrp2.saix.net>, js******@mweb.co.za enlightened
us with...
this.jumpURL = function(url, target) {
if(url) target.location.href = url;


this.jumpURL = function(url, target) {
if (url) {
if (!target) {
// call the default frame "main" or something
target = "main";
}
top.frames[target].document.location.href = url;
}
}

And do note that while vb comparisons and assignments both use the "=" sign,
javascript uses "=" for assignment and "==" for comparisons. A little tip for
you. ;)

--
--
~kaeli~
With her marriage, she got a new name and a dress.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
Hi kaeli

Many thanks for the info.

However, is the line target = "main" not assigning a value ( "main" ) to
the variable ( target ) ?
What I want is to have the href statement to use a value 'passed' to the
function in the "this.jumpURL" line.

We may have up to 6 different InLine Frames ( iFrames ) on our page, and
each menu item passes the URL and target to the jumpURL function.
The target can be any one of the 6 iFrames.

I have hard coded the function for now as follows :

this.jumpURL = function(url, target) {

var targetF = "(Default)" // the default is the BodyFrame iFrame
var targetS = "same" //target is same window
var targetN = "_new" //target is a new window
var NoURL = "(No URL)" //there is no URL for this menu button to link to
var targetBF = "BodyFrame" // this is the name of 1 of the iFrames

if(url == NoURL){
targetF = "_";
targetS = "_";
targetN = "_";
targetBF = "_";
}

if(target == targetF) if(url) BodyFrame.location.href = url;
if(target == targetBF) if(url) BodyFrame.location.href = url;
if(target == targetS) if(url) document.location.href = url;
if(target == targetN) window.open(url);
but would prefer to find a way to get it to work with the passes target
value.

Regards

DaveO
---------------------------------------------------
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <d6**********@ctb-nnrp2.saix.net>, js******@mweb.co.za
enlightened
us with...
this.jumpURL = function(url, target) {
if(url) target.location.href = url;


this.jumpURL = function(url, target) {
if (url) {
if (!target) {
// call the default frame "main" or something
target = "main";
}
top.frames[target].document.location.href = url;
}
}

And do note that while vb comparisons and assignments both use the "=" sign,
javascript uses "=" for assignment and "==" for comparisons. A little tip
for
you. ;)

--
--
~kaeli~
With her marriage, she got a new name and a dress.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
Jul 23 '05 #3

P: n/a
<script>
function jump(url,Target,I){
// I == n for a Frame
if (I == 'n'){
top.frames[Target].location = "http://"+url
}
// I = y for an iframe
if (I == 'y'){
frames[Target].location.href = "http://"+url
}
// I is left blank for normal target
if (I ==''){
window.open("http://"+url, Target,'');
}
}
</script>
<a href="javascript:jump('www.download.com','free','n ')">Frame</a><br>
<a href="javascript:jump('www.www.sue.com','sue','y') ">Iframe</a><br>
<a href="javascript:jump('www.ghost.com','spook','')" >Target</a><br>

--
BootNic Friday, May 20, 2005 12:23 PM

The world is very different now. For man holds in his mortal hands the power to abolish all forms of
human poverty, and all forms of human life.
*John Fitzgerald Kennedy, Inaugural Address*
"DaveO" <js******@mweb.co.za> wrote:
news:d6**********@ctb-nnrp2.saix.net....

Hi kaeli

Many thanks for the info.

However, is the line target = "main" not assigning a value (
"main" ) to the variable ( target ) ?
What I want is to have the href statement to use a value 'passed' to
the function in the "this.jumpURL" line.

We may have up to 6 different InLine Frames ( iFrames ) on our page,
and each menu item passes the URL and target to the jumpURL function.
The target can be any one of the 6 iFrames.

I have hard coded the function for now as follows :

this.jumpURL = function(url, target) {

var targetF = "(Default)" // the default is the BodyFrame iFrame
var targetS = "same" //target is same window
var targetN = "_new" //target is a new window
var NoURL = "(No URL)" //there is no URL for this menu button to
link to var targetBF = "BodyFrame" // this is the name of 1 of the
iFrames

if(url == NoURL){
targetF = "_";
targetS = "_";
targetN = "_";
targetBF = "_";
}

if(target == targetF) if(url) BodyFrame.location.href = url;
if(target == targetBF) if(url) BodyFrame.location.href = url;
if(target == targetS) if(url) document.location.href = url;
if(target == targetN) window.open(url);
but would prefer to find a way to get it to work with the passes
target value.

Regards

DaveO
---------------------------------------------------
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <d6**********@ctb-nnrp2.saix.net>, js******@mweb.co.za
enlightened
us with...
this.jumpURL = function(url, target) {
if(url) target.location.href = url;


this.jumpURL = function(url, target) {
if (url) {
if (!target) {
// call the default frame "main" or something
target = "main";
}
top.frames[target].document.location.href = url;
}
}

And do note that while vb comparisons and assignments both use the
"=" sign, javascript uses "=" for assignment and "==" for
comparisons. A little tip for
you. ;)

--


Jul 23 '05 #4

P: n/a
Hi All

Many Thanks for the solution.

Your kindness is appreciated greatly.

Regards

DaveO

---------------------------------------------------
"BootNic" <Bo*****@bounce.prodigy.net> wrote in message
news:tb*****************@newssvr17.news.prodigy.co m...
<script>
function jump(url,Target,I){
// I == n for a Frame
if (I == 'n'){
top.frames[Target].location = "http://"+url
}
// I = y for an iframe
if (I == 'y'){
frames[Target].location.href = "http://"+url
}
// I is left blank for normal target
if (I ==''){
window.open("http://"+url, Target,'');
}
}
</script>
<a href="javascript:jump('www.download.com','free','n ')">Frame</a><br>
<a href="javascript:jump('www.www.sue.com','sue','y') ">Iframe</a><br>
<a href="javascript:jump('www.ghost.com','spook','')" >Target</a><br>

--
BootNic Friday, May 20, 2005 12:23 PM

The world is very different now. For man holds in his mortal hands the power
to abolish all forms of
human poverty, and all forms of human life.
*John Fitzgerald Kennedy, Inaugural Address*
"DaveO" <js******@mweb.co.za> wrote:
news:d6**********@ctb-nnrp2.saix.net....

Hi kaeli

Many thanks for the info.

However, is the line target = "main" not assigning a value (
"main" ) to the variable ( target ) ?
What I want is to have the href statement to use a value 'passed' to
the function in the "this.jumpURL" line.

We may have up to 6 different InLine Frames ( iFrames ) on our page,
and each menu item passes the URL and target to the jumpURL function.
The target can be any one of the 6 iFrames.

I have hard coded the function for now as follows :

this.jumpURL = function(url, target) {

var targetF = "(Default)" // the default is the BodyFrame iFrame
var targetS = "same" //target is same window
var targetN = "_new" //target is a new window
var NoURL = "(No URL)" //there is no URL for this menu button to
link to var targetBF = "BodyFrame" // this is the name of 1 of the
iFrames

if(url == NoURL){
targetF = "_";
targetS = "_";
targetN = "_";
targetBF = "_";
}

if(target == targetF) if(url) BodyFrame.location.href = url;
if(target == targetBF) if(url) BodyFrame.location.href = url;
if(target == targetS) if(url) document.location.href = url;
if(target == targetN) window.open(url);
but would prefer to find a way to get it to work with the passes
target value.

Regards

DaveO
---------------------------------------------------
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <d6**********@ctb-nnrp2.saix.net>, js******@mweb.co.za
enlightened
us with...
this.jumpURL = function(url, target) {
if(url) target.location.href = url;


this.jumpURL = function(url, target) {
if (url) {
if (!target) {
// call the default frame "main" or something
target = "main";
}
top.frames[target].document.location.href = url;
}
}

And do note that while vb comparisons and assignments both use the
"=" sign, javascript uses "=" for assignment and "==" for
comparisons. A little tip for
you. ;)

--

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.