Change target of links in page

M

Muffinman

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
 
R

Randy Webb

Muffinman said:
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!!!!
 
I

Ivo

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.target='MyOtherFrame';
}
var f=window.frames['MyOtherFrame'].document.links;
var i=f.length;
while(i--){
f.target='MyFirstFrame';
}

This looks repetetive already... I 'm sure it can be improved.
 
M

Muffinman

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

Maarten
 
M

Muffinman

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
 
M

Muffinman

Excellent, works perfect.. thanks.

Maarten
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.target='MyOtherFrame';
}
var f=window.frames['MyOtherFrame'].document.links;
var i=f.length;
while(i--){
f.target='MyFirstFrame';
}

This looks repetetive already... I 'm sure it can be improved.
 
R

Randy Webb

Muffinman said:
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?
 
M

Muffinman

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
 
R

Randy Webb

Muffinman wrote:

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.
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-->
 
M

Muffinman

Randy said:
Muffinman wrote:




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..
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top