Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 08:09:53 PM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 60
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 54
Total: 54

Author Topic: Open url in new tab HELP NEEDED  (Read 12047 times)

0 Members and 1 Guest are viewing this topic.

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 20
Open url in new tab HELP NEEDED
« on: October 21, 2013, 11:08:35 AM »
Hi, i'm trying to make a block with this code:

Code: [Select]
<input name="msg" type="text" /><button>DALE AL CLICK</button>

<script>
    document.querySelector('button').addEventListener('click', function() {
        var msg = document.querySelector('input[name=msg]').value.replace(/ /g, '+');
        location.href = 'http://www.misitio.com/index.php?action=profile;u=' + msg;
    });
</script>



The only I need, is OPEN the url in a new tab, is this possible ?

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Open url in new tab HELP NEEDED
« Reply #1 on: October 21, 2013, 02:00:54 PM »
Browsers treat new windows differently. Some create a new window. Some create a new tab. I don't know of any way that works for all browsers. Besides, you are likely going to piss someone off that like the default behavior of their browser when opening a new link. Your better off just creating a new window and leaving it up to the browser default setting of how it treats new windows vs tabs.

window.open(url,'_blank');


Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 20
Re: Open url in new tab HELP NEEDED
« Reply #2 on: October 21, 2013, 02:11:16 PM »
Ok...

so... Where can I put the "_blank" ?

That's all I need. Otherwise, if can open in a new window is better for me. ;)

Thanks a lot for helping me :)

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Open url in new tab HELP NEEDED
« Reply #3 on: October 21, 2013, 02:20:46 PM »
I already showed you in my last post. :)

Offline Maxx1

  • Sr. Member
  • ****
  • Posts: 352
  • Learning To Fly
    • SMF Theme & Portal Testing
Re: Open url in new tab HELP NEEDED
« Reply #4 on: October 21, 2013, 02:29:14 PM »
I'll spell it out, but some scripts may not allow this:

Code: [Select]
<a target="_blank" href="http://www.mysite.com">link</a>

regards,
Maxx
But Mama, That's Where all the fun is!

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 20
Re: Open url in new tab HELP NEEDED
« Reply #5 on: October 21, 2013, 02:32:01 PM »
IchBin, Sorry ... I didn't see it.

But, using my code...

Is this ok ? ( Because, don't work... steel opening in same window/tab )

Code: [Select]
<input name="msg" type="text" /><button>BUSCAR</button>

<script>
    document.querySelector('button').addEventListener('click', function() {
        var msg = document.querySelector('input[name=msg]').value.replace(/ /g, '+');
window.open(http://www.MYSITE.com/index.php?action=profile;u= + msg,'_blank');
    });

</script>

Maxx1: Thanks, but I need to know where to put the _blank... I don't know where... :(

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Open url in new tab HELP NEEDED
« Reply #6 on: October 21, 2013, 02:44:12 PM »
You forgot a couple of single quotes in your window.open.
window.open('http://www.mysite.com/index.php?action=profile;u=' + msg, '_blank');

That code opens a new tab for me in Chrome and Firefox.
« Last Edit: October 21, 2013, 04:39:59 PM by IchBin™ »

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 20
Re: Open url in new tab HELP NEEDED
« Reply #7 on: October 21, 2013, 02:49:52 PM »
IchBin:

Sorry, but don't work...

Is this code ok ?

Code: [Select]

<input name="msg" type="text" /><button>BUSCAR</button>

<script>
    document.querySelector('button').addEventListener('click', function() {
        var msg = document.querySelector('input[name=msg]').value.replace(/ /g, '+');
window.open("http://www.mysite.com/index.php?action=profile;u=' + msg, '_blank');
</script>


Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 20
Re: Open url in new tab HELP NEEDED
« Reply #8 on: October 21, 2013, 03:13:51 PM »
Hello ? :(

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Open url in new tab HELP NEEDED
« Reply #9 on: October 21, 2013, 04:40:15 PM »
Sorry there was a double quote where there shouldn't be. Try mine again in my last post.