Click to See Complete Forum and Search --> : Get url (newby)
gerjanschoemake
06-28-2004, 03:20 AM
Hello, I'm new on this forum (and also with JavaScript).
I have to write a function to a button but don't know how to do that.
The meaning is to write a function in the header of a HTML page that calls a page in another frame (so just like a link in HTML is like: href="page1.htm" target="framename").
With a press on a button in the HTML page this function supposed to be called, so the page will be opened in the other frame.
Thanx in advange!
Gerjan
use may use various methods, amongst this simplier one:
window.open('newpage.html','frameneame')
or:
top.frames['framename'].location.href='newpage.html'
gerjanschoemake
06-28-2004, 04:51 AM
Hey Cor,
First of all tnx for your reply. I tried to put your code in my file with some help from my js book. But because off my less experience with JS, it does not work correctly. I tried the following (a page within my frameset):
--------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="JavaScript">
function OpenPage(loadframe)
{
thepage = window.open('bestellijst.htm#kaas','content');
}
</script>
</head>
<body>
<a href="javascript:OpenPage">load frame</a>
</body>
</html>
-----
When I test this I get a blank page (within the same frame) with the following text:
function OpenPage(loadframe) { thepage = window.open
('bestellijst.htm#kaas','content'); }
Could you tell me what I'm doing wrong?
Tnx
<a href="javascript:OpenPage()">load frame</a>
and, as you wrote the code I don't see the use of the "loadframe" paramater. unless you have multiple parameters and multimple handlers. Thus the code will be:
<a href="javascript:OpenPage('bestellijst.htm#kaas')">load frame</a>
and
<script language="JavaScript">
function OpenPage(loadframe)
{
thepage = window.open(loadframe,'content');
}
</script>
But... Is there a strong reason to use javascript instead of simple HTML code? Some clients might have javascript disabled, you know...
gerjanschoemake
06-28-2004, 06:55 AM
There is a strong (strange) reasen indead doing this with JS.
This is because Flash has an bug in it's decoder. Therefore it's not possible to use 'name anchors' in an url:
http://www.macromedia.com/support/flash/ts/documents/named_anchors.htm
At the end I will replace the 'load frame' link with a Flash button.
Then it will be possible when I call a Javascript function doing this.
Therefore I must use the first function you gave me, so the named anchor (besellijst.htm#kaas) is not in the 'get url':
<a href="java script:OpenPage()">load frame</a>
I tried both functions, but I cant get neither of them to work correctly.
I enclosed the file. It would be nice if you take a look (and make some changes :-) to this file. Tnx
gerjanschoemake
06-28-2004, 06:56 AM
sorry, was forgotten the file :D
it is because you wrote "javascript:..." with a space between java and script. This forum makes automatically this split for unknown reasons...:-)
Replace that space, write javascript in a single word and it will work
the exact code should be
<a href="javascript:void(OpenPage('bestellijst.htm#kaas'))">load frame</a>
be cause is safer to anounce browser that it should ignore the usual behaviour of the a href HTML action.
You may also use the variant:
<a href="#" onclick="OpenPage('bestellijst.htm#kaas');return false">load frame</a>
Where return false will prevent the normal HTML action a href, so it doesn't matter if flash will or will not use # name...
gerjanschoemake
06-30-2004, 04:03 AM
Tnx Kor, it worked!