Welcome Guest, Not a member yet? Register   Sign In
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

(This post was last modified: 07-18-2020, 02:51 PM by richb201.)

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

(This post was last modified: 07-18-2020, 04:52 PM by richb201.)

(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

(This post was last modified: 07-30-2020, 12:33 AM by richb201.)

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/'ht...oogle.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

(This post was last modified: 07-30-2020, 08:03 AM by richb201.)

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




Theme © iAndrew 2016 - Forum software by © MyBB