SitePoint Sponsor |
|
User Tag List
Results 1 to 20 of 20
Thread: Perl and Javascript question
-
Mar 19, 2001, 23:16 #1
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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: Link241http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 19, 2001, 23:32 #2
- Join Date
- Feb 2001
- Location
- Van down by the river
- Posts
- 254
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Mar 19, 2001, 23:53 #3
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you so much.
And the perl question?http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 20, 2001, 00:15 #4
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, for the javascript, how would I do it if there was bookmarks in the child window?
Thanks
Bryanhttp://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 20, 2001, 22:00 #5
- Join Date
- Feb 2001
- Location
- Van down by the river
- Posts
- 254
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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>
-
Mar 21, 2001, 01:13 #6
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
Bryanhttp://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 21, 2001, 13:16 #7
- Join Date
- Feb 2001
- Location
- Van down by the river
- Posts
- 254
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Mar 21, 2001, 23:18 #8
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 21, 2001, 23:22 #9
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
Bryanhttp://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 23, 2001, 00:40 #10
- Join Date
- Feb 2001
- Location
- Van down by the river
- Posts
- 254
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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!
-
Mar 23, 2001, 00:48 #11
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
wow, thank you so much.
Bryanhttp://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 23, 2001, 01:03 #12
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, that worked perfectly in Internet Explorer but not in Netscape... I run NS 4.6, it should work... any ideas?
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 23, 2001, 19:12 #13
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 24, 2001, 14:36 #14
- Join Date
- Feb 2001
- Location
- Van down by the river
- Posts
- 254
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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>
-
Mar 25, 2001, 10:32 #15
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks so much! It worked!
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 25, 2001, 22:21 #16
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, can anyone help with the Perl question?
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 26, 2001, 21:45 #17
- Join Date
- Aug 2000
- Location
- Silicon Valley
- Posts
- 2,241
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
-
Mar 27, 2001, 21:16 #18
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yep, that's all I needed, thanks!
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 27, 2001, 21:27 #19
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Let me test it out and see if it works
Last edited by Link241; Mar 27, 2001 at 21:29.
http://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
-
Mar 28, 2001, 18:53 #20
- Join Date
- Mar 2001
- Location
- California (I hate it here)
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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>
thankshttp://beyondgaming.cjb.net [The best damn boards you'll find. Beyond Gaming.]
Bookmarks