Jason28 Posted July 17, 2010 Share Posted July 17, 2010 Hello, could anyone please provide me with a working example of a javascript that detects all of the active urls on the page and opens them in another window but has the option of opening all links normally? (without target="_blank"). So someone can click a link to disable links opening in a new window, but on default they will open in a new window. Could you please provide a working example? Thanks. Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/ Share on other sites More sharing options...
trq Posted July 18, 2010 Share Posted July 18, 2010 Would be easy enough to do using jQuery. Something like.... var newwindow = 'on'; // set this via a form or whatever. $(document).ready(function() { $('a').each(function() { if (newwindow == 'on') { $(this).attr('target', '_blank'); } else { $(this).attr('target', '_self'); } }); }); Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/#findComment-1087761 Share on other sites More sharing options...
Jason28 Posted July 18, 2010 Author Share Posted July 18, 2010 Thanks for replying. Could you please provide me with the html to use along with this javascript? A link that would change the text like "open links in same window" and when clicked, it changes to "open links in new window"? Thanks. Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/#findComment-1087768 Share on other sites More sharing options...
trq Posted July 18, 2010 Share Posted July 18, 2010 I'm not here to pump out code for people. Take a look at jQuery's toggle method. You could easily apply that to a button which would switch the 'newwindow' var from 'on' to 'off'. Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/#findComment-1087773 Share on other sites More sharing options...
Jason28 Posted July 18, 2010 Author Share Posted July 18, 2010 Well sorry but I tried learning how to do this for many years but I just do not understand it. If you only give me part of the code I cannot do anything with it. I understand you do not have to do anything, but this is just a waste of time for us since I cannot do anything with half of a script. Could anyone else help please? Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/#findComment-1087781 Share on other sites More sharing options...
RichardRotterdam Posted July 18, 2010 Share Posted July 18, 2010 but this is just a waste of time for us since I cannot do anything with half of a script. The script that was posted previously was pretty much the whole thing written out for you except for a button/link that changes the status of a variable. Can you post what you have tried so far? Most likely no one is going to help much if you don't show have put in a bit of effort yourself Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/#findComment-1087828 Share on other sites More sharing options...
trq Posted July 18, 2010 Share Posted July 18, 2010 Well sorry but I tried learning how to do this for many years but I just do not understand it. If you only give me part of the code I cannot do anything with it. I understand you do not have to do anything, but this is just a waste of time for us since I cannot do anything with half of a script. Could anyone else help please? Go hire someone then. Link to comment https://forums.phpfreaks.com/topic/208043-allow-links-to-open-in-new-window-with-onoff-feature/#findComment-1087893 Share on other sites More sharing options...
Recommended Posts