FeedForAll Forum Index  
 Home  •  FAQ  •   Search   •  Register   •  Profile   •  Log in
 How to obtain Open Link in new window View next topic
View previous topic
Post new topicReply to topic
Author Message
publimedia01



Joined: 21 Apr 2009
Posts: 7

PostPosted: Wed Apr 22, 2009 7:26 am Reply with quoteBack to top

Hi:

Anybody knows if it's possible to have links opened in new window with RSS2HTML.
All is working fine but when I click on a News Link, this it's opened in the same window. Can I modify the code in order to force the links to be opened in a new window.

I've been testing the RSS to HTML page generator of rssinclude.com . I created RSS widgets with PHP code and Javascript code, selecting the option "Open in new window" in both widgets.
Javascript widget was working fine opening all links in a new window but PHP widget was opening links in the same window, despite the fact that I selected the option "Open in new window".

So I guess if it's possible to open links in a new window, changing the code in RSS2HTML.php or if this is only possible with Javascript coding.

Thank You
David
View user's profile
damian0612



Joined: 30 Jun 2006
Posts: 133

PostPosted: Wed Apr 22, 2009 8:12 am Reply with quoteBack to top

David

You can do this in your template.html using target="_blank":

Code:

<A href="~~~ItemLink~~~" target="_blank">~~~ItemTitle~~~</A>


cheers
Damian
View user's profile
publimedia01



Joined: 21 Apr 2009
Posts: 7

PostPosted: Wed Apr 22, 2009 11:39 am Reply with quoteBack to top

Thanks Damian:

I tried your solution with Google Rss Feed News. Only the title links of the news open in a new window but not other links like those that are at the end of the news description.

I tried other solution inserting this javascript code in the <head> tag of my RSS template:

----------------------------
<script>
onload = function() {
var frame = parent.frames[0].document;
var links = frame.getElementsByTagName('a');
for (var i=0; i<links.length; ++i) {
links[i].setAttribute('target','_blank');
}
}
</script>
----------------------------

With this script all the links of the news open in a new window, but the problem now is that also my website links open in new window when there is a RSS news feed included.


Finally, I tried other solution.
I put the above script on the <head> tag of a new page where I included the RSS feed (called rssfeed.php). Then I inserted rssfeed.php into a <iframe> in my website page. With this solution my website links open in the same window and all RSS News links open in a new window. So this could be a solution.

But the problem now is that all RSS News are included in <iframe> so web searchers like google will not recognise them.

I will still look for a solution.
Thank you for your help.
David
View user's profile
agallo33



Joined: 04 Jun 2007
Posts: 21

PostPosted: Mon Apr 27, 2009 4:24 pm Reply with quoteBack to top

Same issue here. I wasn't able to get your javascript code snippet working for the redirect. Don't think I am missing anything. Here's is what I have in my sample.html code.



Code:

<HTML>
    <HEAD>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
onload = function() {
var frame = parent.frames[0].document;
var links = frame.getElementsByTagName('a');
for (var i=0; i<links.length; ++i) {
links[i].setAttribute('target','_blank');
}
}
</script>
        <TITLE>
            ~~~FeedTitle~~~
        </TITLE>
    </HEAD>
    <BODY>
        <H1>~~~FeedTitle~~~</H1>
        <H2>~~~FeedDescription~~~</H2>
        <BR>
        <TABLE width="100%">
            ~~~BeginItemsRecord~~~
            <TR>
                <TD>
                    ~~~ItemPubShortDate~~~ ~~~ItemPubShortTime~~~
                </TD>
            </TR>
            <TR>
                <TD>
                    <B><A href="~~~ItemLink~~~" target="_blank">~~~ItemTitle~~~</A></B>
                </TD>
            </TR>
            <TR>
                <TD bgcolor="#FFFFFF">
                    ~~~ItemDescription~~~
                    <BR>
                </TD>
            </TR>
            ~~~EndItemsRecord~~~
        </TABLE>
    </BODY>
</HTML>
View user's profile
publimedia01



Joined: 21 Apr 2009
Posts: 7

PostPosted: Tue Apr 28, 2009 5:15 am Reply with quoteBack to top

Hi,

I made a mistake in my previous post. The code must be included into the page where you are putting your RSS feeds not in the RSS2HTML sample page.

I will explain it better again:

HOW TO FORCE ALL LINKS TO BE OPENED IN A NEW WINDOW:

If you are using an RSS software conversion like RSS2HTML, and you want all links of the RSS feeds that you have inserted into your page, to be opened in a new window, you have 2 solutions depending on your webpage configuration.
For the explanation, I will call the page where we want to insert the RSS Feeds “myfeeds.php

SOLUTION 1: If myfeeds.php is embedded in other main page through a frame or an iframe (that is the case when you include a webpage in Joomla! throw the “wrapper” module), you just need to put the following code into the <head> tag of myfeeds.php:

<script>
onload = function() {
var frame = parent.frames[0].document;
var links = frame.getElementsByTagName('a');
for (var i=0; i<links.length; ++i) {
links[i].setAttribute('target','_blank');
}
}
</script>


SOLUTION 2: If myfeeds.php is a simple and single page then you need to put the following code into the <head> tag of myfeeds.php:

<script>
onload = function() {
var frame = parent.document;
var links = frame.getElementsByTagName('a');
for (var i=0; i<links.length; ++i) {
links[i].setAttribute('target','_blank');
}
}
</script>


As you can see the only difference between solution 1 and 2 is in this sentence:
var frame = parent.frames[0].document;
This sentence works when myfeeds.php is embedded into another page.
But when myfeeds.php is not embedded into another page you must change it with this sentence: var frame = parent.document;

HOW TO KEEP SOME LINKS OPENING IN THE SAME WINDOW

With both solutions 1 and 2, all your webpage links will be opened in a new window, not only the RSS Feeds links. So, If you only want your RSS Feeds links to be opened in a new window and keep you other web links (like navigation or menu links) opening in the same window, you need to insert this javascript code in all links that you want to open in the same window:
<a href="javascript:window.location.href='page.php';">


I apologize for my poor english but I'm italian.
I hope this will help you.
By.
David
View user's profile
agallo33



Joined: 04 Jun 2007
Posts: 21

PostPosted: Tue Apr 28, 2009 10:43 am Reply with quoteBack to top

Thanks so much David for your response to my inquiry regarding opening in a new window. I was able to use the second js option which did resolve the issue of redirecting the current page.

I then tried your javascript idea to handle the menu or any other links I did not want to open in a new window. Unfortunately I did not have any luck with this option and wonder if I missed something. Here's what I have for one of my menu items.

Code:

<li id="current"><a href="javascript:window.location.href='index.php';" title="Home"><span>Recently Added</span></a></li>
View user's profile
publimedia01



Joined: 21 Apr 2009
Posts: 7

PostPosted: Tue Apr 28, 2009 12:18 pm Reply with quoteBack to top

Hello again:

I apologize. I only tested that script in Google Chrome browser and it worked, but not in Internet Explorer.
I found a new solution that it’s working in Google Chrome, Firefox and Internet Explorer.

So, the solution to keep your navigation links opening in the same window with this script:
<a href="javascript:window.location.href='page.php';"> doesn’t work in Internet Explorer. Forget that script and follow the following instructions:

1)

You have used the second solution to have all you RSS feeds links opening in a new window, inserting the following script inside the <head> tag of myfeeds.php:

<script>
onload = function() {
var frame = parent.document;
var links = frame.getElementsByTagName('a');
for (var i=0; i<links.length; ++i) {
links[i].setAttribute('target','_blank');
}
}
</script>


2)

Now you want to keep some of your web links opening in the same window. Ok!

First:

You need to put the following script inside the <head> tag of myfeeds.php:

<script type="text/javascript">
function goToURL() {
var i, args=goToURL.arguments; document.returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>


Second:

You need to put this script in each link you want to keep opening in the same window:

<a href="page.php" onclick="goToURL('parent','page.php');return document.returnValue">PAGE</a>

This solution will work with Google Chrome, Firefox and Internet Explorer.

One comment:

If you need to use the first solution for RSS News Feeds using frames (see post above). The solution to keep some web links opening in the same window is practically the same.
The script you have to put into the head tag is the same and you only have to change 'parent' and put 'self' in the link you want to be opened in the same window.

I hope this will work for you.
Bye.
David.
View user's profile
agallo33



Joined: 04 Jun 2007
Posts: 21

PostPosted: Tue Apr 28, 2009 4:20 pm Reply with quoteBack to top

Works great :) Thanks David for the help!
View user's profile
Gio



Joined: 08 Jul 2012
Posts: 1

PostPosted: Sun Jul 08, 2012 7:34 am Reply with quoteBack to top

I can't get it to work with the script in the head. I'm using frames to include "mypage.php". Since the thread here is 3 years old could it be that it don't work with newer browser?
View user's profile
Tech Support



Joined: 27 Aug 2004
Posts: 2791

PostPosted: Mon Jul 09, 2012 7:20 am Reply with quoteBack to top

The script does work with all current versions of all current browsers. Could you give us a little more information on what you're trying to do and what errors you might be receiving?

_________________
Create RSS Feeds
Audio Recording and Editing
View user's profile
Display posts from previous:      
Post new topicReply to topic


 Jump to:   



View next topic
View previous topic


Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme