• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to open a new tab in the browser

#1
I am trying to open a new tab in the browser. I tried using the code below directly in the controller but I am getting a message "popup blocked". I really don't want a popup. I just want to open another tab that is set to https://patents.google.com/


echo '<script type="text/javascript">
  window.open("https://patents.google.com/");
</script>';


Anyone know how to accomplish this? 
proof that an old dog can learn new tricks
Reply

#2
where is the function that will trigger the JS ?

I think it should be like this
Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
</head>
<body>
    <button onclick="openTab()" type="button" class="btn btn-primary">Primary</button>

    <script>
        function openTab() {
            window.open('https://duckduckgo.com/?t=ffab', '_blank');
        }
    </script>
</body>
</html>

here the openTab() function will trigger whats inside it when called via the onclick attribute. You just echoed the window.open line , i dont think this will work.
Increase Your Awareness
Reply

#3
Thanks. In the controller.  Does that code go directly in the controller?
proof that an old dog can learn new tricks
Reply

#4
I was wrong regarding that you should use a function to execute this line

window.open('https://duckduckgo.com/?t=ffab', '_blank');


i tried it directly in the controller and it worked


<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Controller1 extends Controller
{
    public function index()
    {
        echo "
            <script>
                window.open('https://duckduckgo.com/?t=ffab', '_blank');
            </script>
            ";
    }   

}


but firefox told me that its preventing popups , so i enabled them for localhost , maybe you are disabling them.
Increase Your Awareness
Reply

#5
(07-18-2020, 03:01 PM)BlackBanana Wrote: I was wrong regarding that you should use a function to execute this line

window.open('https://duckduckgo.com/?t=ffab', '_blank');


i tried it directly in the controller and it worked


<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Controller1 extends Controller
{
    public function index()
    {
        echo "
            <script>
                window.open('https://duckduckgo.com/?t=ffab', '_blank');
            </script>
            ";
    }   

}


but firefox told me that its preventing popups , so i enabled them for localhost , maybe you are disabling them.

Worked great. thanks.
proof that an old dog can learn new tricks
Reply

#6
Well I decided that I want to give the user control over opening the window. I have added this button to my screen;

<div style=”float:left”>
    <button onclick="document.location='\'https://patents.google.com/\''">Open Google Patents</button>
</div>

But clicking this causes this path to open: http://localhost/index.php/Configure/'https://patents.google.com/'
when I really want just https://patents.google.com
proof that an old dog can learn new tricks
Reply

#7
Code:
<button class="btn btn-primary btn-lg" onclick="location.href='https://patents.google.com/'">Open Google Patents</button>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#8
thx. That worked. One thing, I'd like to open Google Patents in a new tab. How can I change that?

I tried this mod

<button class="btn btn-primary btn-lg" onclick="location.href='https://patents.google.com/','_blank'">Open Google Patents</button>

but it still opens in the same tab
proof that an old dog can learn new tricks
Reply

#9
Add this to it:

Code:
target="_blank"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#10
I am getting the same thing:
<div style=”float:left”>
<button class="btn btn-primary btn-lg" onclick="location.href='https://patents.google.com/',target='_blank'">Open Google Patents</button>
</div>
proof that an old dog can learn new tricks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.