-
I have 2 questions. One is a perl question and the other is a Javascript question.
First the Perl question:
I need a script that will find something in an HTML document and replace it with something else. For example:
The script will replace "Receive" with "Recieve".
and the Javascript question:
I need a Javascript that will detect if a window is open. If it is opened, it just brings it up. If it isn't open, then it opens it.
For example: If someone clicks the "Help" link, and then they minimize it, and click the link again, then it will just bring up the already-opened window, and will not pop up a new window.
Thanks!
Bryan
AIM: Link241
-
To open a new window, you can use a function like this:
<script language="JavaScript">
<!--
function openWindow() {
popupWin = window.open('http://www.google.com/', 'myWindow', 'scrollbars,resizable,width=640,height=480')
}
-->
</script>
Call the script by adding an onClick to a form button or a link:
<a href="#" onClick="openWindow();return false;">Google</a>
Then in your child window (the popup window), use this:
<script language="JavaScript">
<!--
window.focus();
-->
</script>
No need to check to see if the window is open, since you gave it the name 'myWindow' in the function. If it's not open, it opens, if it's already open, it brings the window to the front.
-
Thank you so much.
And the perl question?
-
Ok, for the javascript, how would I do it if there was bookmarks in the child window?
Thanks
Bryan
-
I'm not sure exactly what you mean, so let me read your mind for a moment... :)
Are you wanting to click links in the popup and have them open in the parent window? If so, there are a few ways to do it. Here's one...
<a href="http://www.google.com" onClick="window.opener.location.href = 'http://www.google.com';return false;">Google</a>
-
No...
I mean, on the parent page, there would be links to different bookmarks on the child page (like #bottom #top etc.). I tried this and when you click the link, it goes there on the child page, but the child page doesn't pop up.
Thanks
Bryan
-
Make sure that this JavaScript is in the child window:
<script language="JavaScript">
<!--
window.focus();
-->
</script>
Then, as long as you're correctly calling the child from the parent, the child window will pop to the front when it's called.
-
Yes, I have that, but it doesn't pop up. It goes to the bookmark on the page, but the child window doesn't pop up... any ideas?
-
Ok, I'll show you waht I have, and you can fix it:
This is the parent window:
<html>
<head>
<title>CHA</title>
<script language="JavaScript">
<!--
function openHelp() {
popupWin = window.open('chatest2.html#Helpdown', 'help', 'width=300,height=400,top=0,left=0,menubar=0,location=0,scrollbars=1,directories=0,status=0,toolbars=0,resizable=0')
}
-->
</script>
<script language="javascript">
<!--
function openHelp2(){
popupWin = window.open('chatest2.html#Helpfurtherdown', 'help', 'width=300,height=400,top=0,left=0,menubar=0,location=0,scrollbars=1,directories=0,status=0,toolbars=0,resizable=0')
}
-->
</script>
</head>
<body>
<a href="" onClick="openHelp();return false;">Help, down the page</a>
<a href="" onClick="openHelp2();return false;">Help, further down the page</a>
</body>
</html>
This is the child window:
<html>
<head>
<title>CHA</title>
<script language="JavaScript">
<!--
window.focus();
-->
</script>
</head>
<body>
Help page.<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><a name="#Helpdown">Help, but down the page.</a><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><a name="#HelpfurtherDown">Help, but even further down the page.</a><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>
K, what happens it discribed in my post above... please help!
Thanks
Bryan
-
OK, I see. It must be something with the anchors, because the window.focus() in the child window usually works.
Plan B: You can remove the window.focus() from the child window, and just add this line to your openHelp function after opening the window...
popupWin.focus();
By the way, if you're going to be linking to that window a lot, you could use one function to do it, and pass the name of the anchor you want to use to the function...
<script language="JavaScript">
<!--
function openHelp(whichAnchor) {
popupWin = window.open('chatest2.html#' + whichAnchor, 'help', 'width=300,height=400,top=0,left=0,menubar=0,location=0,scrollbars=1,directories=0,status=0,toolbars=0,resizable=0')
popWin.focus();
}
-->
</script>
And then pass the anchor name in your call to the function...
<a href="" onClick="openHelp('Helpdown');return false;">Help, down the page</a>
<a href="" onClick="openHelp('Helpfurtherdown');return false;">Help, further down the page</a>
That should do it!
-
wow, thank you so much.
Bryan
-
Ok, that worked perfectly in Internet Explorer but not in Netscape... I run NS 4.6, it should work... any ideas?
-
What happens in Netscape is, it opens up the window, but just goes straight to the bottom. Then if you minimize it and click another link, it brings up the window, but it's still at the bottom. I think Netscape's not recognizing the bookmarks. I have them like this: <a name="#bm">Word</a>, it might not work in netscape. Any ideas?
-
I haven't tested it, but I seem to remember Netscape having a problem with using the # symbol in the name of the anchor. Try naming your anchor 'bm', without the #. But in your links of course, you'd refer to the anchor as #bm...
<a href="myPage.html#bm">To anchor</a>
-
Thanks so much! It worked!
-
Ok, can anyone help with the Perl question?
-
Assume you know a bit about Perl :)
Code:
$text = "Blah, blah, receive receive and receive";
$text =~ s/receive/recieve/g;
print $text;
# output: Blah, blah, recieve recieve and recieve
-
Yep, that's all I needed, thanks!
-
Let me test it out and see if it works
-
Hmmm.... can you write me up an example? I can't seem to get it to work... I want to change
<b>Link241</b> to <big>Link241</big>
thanks