467,169 Members | 1,031 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,169 developers. It's quick & easy.

Change target of links in page

Hi,

I have a webpage with two Iframe's. I want to be able to change the
target of all links in one frame so it will point to the other frame and
all this from the main page. Is this possible and if so how?

Thanks in advance, Maarten

Jul 23 '05 #1
  • viewed: 5304
Share:
9 Replies
Muffinman wrote:
Hi,

I have a webpage with two Iframe's. I want to be able to change the
target of all links in one frame so it will point to the other frame and
all this from the main page. Is this possible and if so how?


Yes its possible.

Open all your pages in a text editor.
Search and replace the target="" attributes to what you want them to be.
Save all your pages.
Reupload all your pages.

Now, they are targeted properly.

Look Ma, no Javascript!!!!

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Ivo
"Muffinman" wrote

I have a webpage with two Iframe's. I want to be able to change the
target of all links in one frame so it will point to the other frame and
all this from the main page. Is this possible and if so how?


Make sure your iframes are properly named. Then loop through all links in
them and adjust each link's target property accordingly:

var f=window.frames['MyFirstFrame'].document.links;
var i=f.length;
while(i--){
f[i].target='MyOtherFrame';
}
var f=window.frames['MyOtherFrame'].document.links;
var i=f.length;
while(i--){
f[i].target='MyFirstFrame';
}

This looks repetetive already... I 'm sure it can be improved.
--
Ivo
http://www.vansandick.com/

Jul 23 '05 #3
First place: I'm lazy. Secondly with about a thousand pages and no
target to replace.. this can be rather difficult.

Maarten

Randy Webb wrote:
Muffinman wrote:
Hi,

I have a webpage with two Iframe's. I want to be able to change the
target of all links in one frame so it will point to the other frame
and all this from the main page. Is this possible and if so how?

Yes its possible.

Open all your pages in a text editor.
Search and replace the target="" attributes to what you want them to be.
Save all your pages.
Reupload all your pages.

Now, they are targeted properly.

Look Ma, no Javascript!!!!


Jul 23 '05 #4
First off all: I'm lazy and what I want is usually possible... Secondly:
with over a thousand pages and no target pressent to change, this can be
rather difficult.

MI

Randy Webb wrote:
Muffinman wrote:
Hi,

I have a webpage with two Iframe's. I want to be able to change the
target of all links in one frame so it will point to the other frame
and all this from the main page. Is this possible and if so how?

Yes its possible.

Open all your pages in a text editor.
Search and replace the target="" attributes to what you want them to be.
Save all your pages.
Reupload all your pages.

Now, they are targeted properly.

Look Ma, no Javascript!!!!


Jul 23 '05 #5
Excellent, works perfect.. thanks.

Maarten

Ivo wrote:
"Muffinman" wrote
I have a webpage with two Iframe's. I want to be able to change the
target of all links in one frame so it will point to the other frame and
all this from the main page. Is this possible and if so how?

Make sure your iframes are properly named. Then loop through all links in
them and adjust each link's target property accordingly:

var f=window.frames['MyFirstFrame'].document.links;
var i=f.length;
while(i--){
f[i].target='MyOtherFrame';
}
var f=window.frames['MyOtherFrame'].document.links;
var i=f.length;
while(i--){
f[i].target='MyFirstFrame';
}

This looks repetetive already... I 'm sure it can be improved.
--
Ivo
http://www.vansandick.com/


Jul 23 '05 #6
Muffinman wrote:
First off all: I'm lazy and what I want is usually possible... Secondly:
with over a thousand pages and no target pressent to change, this can be
rather difficult.


Your laziness is obvious by your lack of ability to scroll down, snip,
and reply in order. But I wouldn't expect you to understand that.

As for cycling through all your links, what target attribute will they
have if the user has JS disabled?

Furthermore, it is trivial to install Apache and PHP on a PC and then
write a PHP script that will search all pages, remove all target
attributes (if present) and then search them all again and add the
target attribute. But of course, you are too lazy for that, right?

If you are that lazy, then why should we waste our time to answer you?

P.S. Read the FAQ via the signature. That is, if you are not too lazy to
scroll down that far.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #7

Your laziness is obvious by your lack of ability to scroll down, snip,
and reply in order. But I wouldn't expect you to understand that.
That's more on how I prefer to answer messages.

As for cycling through all your links, what target attribute will they
have if the user has JS disabled?
Than that user has to enable that. The site won't work anyway without JS
and it can't be done without JS or at least it will make it a lot harder
for the user. I'm not writing a conventional web site but more a sort
of/part of, program..

Furthermore, it is trivial to install Apache and PHP on a PC and then
write a PHP script that will search all pages, remove all target
attributes (if present) and then search them all again and add the
target attribute. But of course, you are too lazy for that, right?
I considered that but since I can not know which pages exactly have to
be changed this is not an option. BTW. all these pages have been created
with php.

If you are that lazy, then why should we waste our time to answer you?
That's up to you. Laziness knows a few forms. For me it meant learning a
whole lot more than I initially intended to do. Unfortunately it is a
lot harder to do without the help of others.

P.S. Read the FAQ via the signature. That is, if you are not too lazy to
scroll down that far.


You make it sound as if laziness is a negative thing, do some more
thinking on that. Most of what we have is build on laziness...
Why does your kind always answer questions so aggressively? (<- These
are usually not my experiences but more on what I read on answers in
various groups )

Well, I am not gonna spend more time on you..

Maarten


Jul 23 '05 #8
Muffinman wrote:

<--snip-->

As for cycling through all your links, what target attribute will they
have if the user has JS disabled?

Than that user has to enable that. The site won't work anyway without JS
and it can't be done without JS or at least it will make it a lot harder
for the user. I'm not writing a conventional web site but more a sort
of/part of, program..


I am not sure I agree with the "lot harder for the user". User clicks a
button/link, something happens. Its no harder on the user whether the
action comes from a script or a server. The difference a JS dependency
makes is on the load on the server versus the client. But its moot. The
fact that you are creating an intra-net type application makes a huge
difference in the responses you get in this group.

Furthermore, it is trivial to install Apache and PHP on a PC and then
write a PHP script that will search all pages, remove all target
attributes (if present) and then search them all again and add the
target attribute. But of course, you are too lazy for that, right?

I considered that but since I can not know which pages exactly have to
be changed this is not an option. BTW. all these pages have been created
with php.


Its a lot simpler to let PHP handle it before the page is sent to the
browser than it is for JS to handle it. It would only take one pass of
PHP through every file, replace the target's and save the files. Then it
never has to be done again. But when its served with one target and JS
has to change it, it has to do it every single time the page is loaded.

<--snip-->

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #9


Randy Webb wrote:
Muffinman wrote:

<--snip-->

As for cycling through all your links, what target attribute will
they have if the user has JS disabled?
Than that user has to enable that. The site won't work anyway without
JS and it can't be done without JS or at least it will make it a lot
harder for the user. I'm not writing a conventional web site but more
a sort of/part of, program..

I am not sure I agree with the "lot harder for the user". User clicks a
button/link, something happens. Its no harder on the user whether the
action comes from a script or a server. The difference a JS dependency
makes is on the load on the server versus the client. But its moot. The


This is what I meant with that you do not know what I am trying to do.
The whole point is to make it an offline application. As I do not have a
internet connection at home and I have access to an online library I
wrote this PHP script to download several books. With javascript I want
to create a menu for easier navigation through the book. Main functions
are working now.. but it still needs some improvement.

fact that you are creating an intra-net type application makes a huge
difference in the responses you get in this group.
I'm not sure what you mean with this. The part of the app. we are
discussing now is completely offline... local..

Furthermore, it is trivial to install Apache and PHP on a PC and then
write a PHP script that will search all pages, remove all target
attributes (if present) and then search them all again and add the
target attribute. But of course, you are too lazy for that, right?


I considered that but since I can not know which pages exactly have to
be changed this is not an option. BTW. all these pages have been created
with php.

Its a lot simpler to let PHP handle it before the page is sent to the
browser than it is for JS to handle it. It would only take one pass of
PHP through every file, replace the target's and save the files. Then it
never has to be done again. But when its served with one target and JS
has to change it, it has to do it every single time the page is loaded.

As I stated before: I can not exactly know which pages have to be edited
exept for that they are somewhere among the first twenty pages.

Maarten

Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lars Schlanbusch | last post: by
16 posts views Thread by Mark van Ballegooijen | last post: by
10 posts views Thread by Richard | last post: by
4 posts views Thread by Richard Cornford | last post: by
Dököll
4 posts views Thread by Dököll | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.